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) {
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) {
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) {
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;
}