Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have an asp.net page, in which i have a repeater where in this repeater i have some 86 rows and each row i have three dropdownlist (rig, well and driver).

Using jquery i have populate these dropdownlist.

Code:
<td>
                                    <asp:DropDownList ID="ddlstatus" CssClass="ddlstatus" runat="server">
                                        <asp:ListItem Value="-1" Text="--Select--" Selected="True"></asp:ListItem>
                                        <asp:ListItem Value="1" Text="Active"></asp:ListItem>
                                        <asp:ListItem Value="0" Text="InActive"></asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlrig" CssClass="ddlrig myRig" runat="server" Width="100px">
                                    </asp:DropDownList>
                                    <asp:HiddenField ID="hdnrig" runat="server" />
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlwell" runat="server" CssClass="ddlwell myWell" Width="100px">
                                    </asp:DropDownList>
                                    <asp:HiddenField ID="hdnwell" runat="server" />
                                </td>
                                <td>
                                    <asp:TextBox ID="txtlocation" CssClass="txtlocation" runat="server" Text='<%# Eval("location")%>'></asp:TextBox>
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddldriver" CssClass="ddldriver myDriver" runat="server" Width="100px">
                                    </asp:DropDownList>
                                    <asp:HiddenField ID="hdndr" runat="server" />
                                </td>


jquery/Ajax
$.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: "VtWebMethod.aspx/GetWell",
                   data: '{"i":"' + 1 + '"}',
                   dataType: "json",
                   success: function (Result) {
                       //alert(Result.d);
                       Result = Result.d;
                       $(".myRig").append($(Result));
                   },
                   error: function (Result) {
                       alert("Error");
                   }
               });
               $.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: "VtWebMethod.aspx/GetWell",
                   data: '{"i":"' + 2 + '"}',
                   dataType: "json",
                   success: function (Result) {
                       //alert(Result.d);
                       Result = Result.d;
                       $(".myWell").append($(Result));
                   },
                   error: function (Result) {
                       alert("Error");
                   }
               });
               $.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: "VtWebMethod.aspx/GetWell",
                   data: '{"i":"' + 3 + '"}',
                   dataType: "json",
                   success: function (Result) {
                       //alert(Result.d);
                       Result = Result.d;
                       $(".myDriver").append($(Result));
                   },
                   error: function (Result) {
                       alert("Error");
                   }
               });




Till now, page is loading successfully, with all dropdownlists.

But when i want to get the selected value in c# or in jquery, in both places it is showing empty/null.

Can anyone please help me. Where i'm wrong or how to get the selected value of a dropdownlist.

Please help me.

Thanks

What I have tried:

webmethod
[WebMethod]
public static string GetWell(int i)
{
    string data="";
    string send = "";
    if (i == 1)
    {
        if (MySession.Current.RigDT.Rows.Count > 0)
        {
            foreach (DataRow dr in MySession.Current.RigDT.Rows)
            {
                data = data + "<option value=" + dr["RigID"].ToString() + ">" + dr["Rig_Name"].ToString() + "</option>";
            }
            send = "<option value=0>--Select--</option>" + data;

        }
    }
    else if (i == 2)
    {
        if (MySession.Current.WellDT.Rows.Count > 0)
        {
            foreach (DataRow dr in MySession.Current.WellDT.Rows)
            {
                data = data + "<option value=" + dr["WellID"].ToString() + ">" + dr["Well_Name"].ToString() + "</option>";
            }
            send = "<option value=0>--Select--</option>" + data;

        }
    }
    else if (i == 3)
    {
        if (MySession.Current.DriverDT.Rows.Count > 0)
        {
            foreach (DataRow dr in MySession.Current.DriverDT.Rows)
            {
                data = data + "<option value=" + dr["RecID"].ToString() + ">" + dr["EmpName"].ToString() + "</option>";
            }
            send = "<option value=0>--Select--</option>" + data;

        }
    }
    return send;
}
Posted
Updated 17-Mar-16 22:20pm
Comments
F-ES Sitecore 16-Mar-16 13:12pm    
If you want to populate the dropdowns using jQuery you can't use asp:Dropdownlist controls, use a normal <select>

However as already advised, just populate the options via your code-behind page. It's easier to control the content of things if you use the data binding events in your code-behind page rather than using mark-up on the aspx page.
Karthik_Mahalingam 18-Mar-16 3:09am    
where do u want to get the selected item value ?
in client side or server side ?

if you are using ASP.NET why not use a collection and bind the well data directly in the C# page rather then using Json.
 
Share this answer
 
Comments
abdul subhan mohammed 17-Mar-16 1:01am    
as i mentioned above, i have 100's of rows and in each row i have 3 dropdowns(min 300 dropdowns to bind, all the time).
to bind these dropdowns using c#.. is taking more time.
so, i used ajax to bind. Its successfully bind also. But the problem is, i'm not these dropdowns values nor text.
Hi abdul,
Since you are using asp:repeater control, the content inside the Item template will be generated dynamically on the UI with no of items in the collection, so each time the control will be created with an unique ID ( eg: MainContent_repeater1_ddlrig_1 )

when you are trying to select the particular drop down list using jquery ID selector you must be careful with the ID's ( right click the page to see the HTML ( view source ) to see the dynamimcally created ID's
suppose if you are selecting the drop down list using Class selector you should specify the index of the matched drop down list
JavaScript
$('.myRig').get(1).val()// gives you the first dropdown list value 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900