使用jquery填充dropdownlist时如何获取dropdownlist选择的值 [英] How to get dropdownlist selected value when dropdownlist populated using jquery

查看:60
本文介绍了使用jquery填充dropdownlist时如何获取dropdownlist选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个asp.net页面,其中我有一个转发器,在这个转发器中我有86行,每行我有三个下拉列表(钻机,井和驱动程序)。



使用jquery我已填充这些下拉列表。



代码:

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



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选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆