无法从使用JQuery绑定的下拉列表中获取值 [英] Can't get value from dropdown which is binded using JQuery

查看:59
本文介绍了无法从使用JQuery绑定的下拉列表中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面加载时使用jquery绑定了下拉列表;但是在选择了该下拉菜单的文本并提交按钮以获取该下拉菜单的值之后,它在服务器端显示为空白.
谁能帮我解决这个问题.
提前谢谢.

这是我通过其绑定下拉列表的Web服务

I have bound dropdown using jquery at the time of page load; but after selecting a text of that dropdown and submit a button to get the value of that dropdown it shows blank on the server side.
Can anyone help me to solve this problem.
Thanks in advance.

Here is the web service through which i am binding dropdown

[WebMethod]
    public static CountryDetails[] BindDatatoDropdown()
    {
        DataTable dt = new DataTable();
        List<countrydetails> details = new List<countrydetails>();

        using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT ID,Name FROM test", con))
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                foreach (DataRow dtrow in dt.Rows)
                {
                    CountryDetails country = new CountryDetails();
                    country.ID = Convert.ToInt32(dtrow["ID"].ToString());
                    country.Name = dtrow["Name"].ToString();
                    details.Add(country);
                }
            }
        }
        return details.ToArray();
    }
public class CountryDetails
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }


通过下面的JQuery,我可以绑定下拉列表,并且可以正常运行


and through this following JQuery i am binding dropdown and it works perferctly

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "AllAccomodation.aspx/BindDatatoDropdown",
            data: "{}",
            dataType: "json",
            success: function (data) {
                $.each(data.d, function (key, value) {
                    $("#ContentPlaceHolder1_typelisting").append($("<option></option>").val(value.ID).html(value.Name));
                });
            },
            error: function (result) {
                alert("Error");
            }
        });
    });

推荐答案

(document).ready(function(){
(document).ready(function () {


.ajax({ 输入:"POST", contentType:"application/json; charset = utf-8", url:"AllAccomodation.aspx/BindDatatoDropdown", 数据: "{}", dataType:"json", 成功:函数(数据){
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "AllAccomodation.aspx/BindDatatoDropdown", data: "{}", dataType: "json", success: function (data) {


.each(data.d,函数(键,值){
.each(data.d, function (key, value) {


这篇关于无法从使用JQuery绑定的下拉列表中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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