使用jquery填充dropdownlist时如何获取dropdownlist选择的值

编程入门 行业动态 更新时间:2024-10-28 02:21:25
本文介绍了使用jquery填充dropdownlist时如何获取dropdownlist选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我有一个asp页面,其中我有一个转发器,在这个转发器中我有86行,每行我有三个下拉列表(钻机,井和驱动程序)。 使用jquery我已填充这些下拉列表。 代码:

Hi guys, I have an asp 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

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

到目前为止,页面已成功加载,所有下拉列表。 但是当我想在c#或jquery中获取所选值时,在这两个地方它都显示为空/ null。 任何人都可以帮助我。哪里我错了或如何获得下拉列表的选定值。 请帮助我。 谢谢 我的尝试: webmethod

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

推荐答案

.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; .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( (".myRig").append(

(Result)); }, error:function(Result){ alert(错误); } }); (Result)); }, error: function (Result) { alert("Error"); } });

更多推荐

使用jquery填充dropdownlist时如何获取dropdownlist选择的值

本文发布于:2023-10-12 03:00:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jquery   dropdownlist

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!