如何使用jquery绑定asp.net中的Dropdownlist?

时间:2013-09-23 09:49:10

标签: c# asp.net

我正在开发一个asp.net应用程序,因为我必须使用jquery将dropdownlist与country_names绑定。我使用了以下代码: -

[WebMethod]
    public static CountryDetails[] BindDatatoDropdown()
    {
        SqlConnection conn = new SqlConnection(@"Data Source=RIZ-PC\SQLEXPRESS;Initial Catalog=Sandeep;Integrated Security=True;");
    conn.Open();
    DataTable dt = new DataTable();
    List<CountryDetails> details = new List<CountryDetails>();

    // SqlCommand cmd = new SqlCommand("SELECT CountryID,CountryName FROM Country", con);

    SqlDataAdapter da = new SqlDataAdapter("SELECT CountryID,CountryName FROM Country", conn);
    da.Fill(dt);
    foreach (DataRow dtrow in dt.Rows)
    {
        CountryDetails country = new CountryDetails();
        country.CountryId = Convert.ToInt32(dtrow["CountryId"].ToString());
        country.CountryName = dtrow["CountryName"].ToString();
        details.Add(country);
    }
    return details.ToArray();
}

public class CountryDetails
{
    public int CountryId { get; set; }
    public string CountryName { get; set; }
}

但它不起作用,当控件进入conn.open()时,它在窗口中显示错误,错误只显示“localhost中的页面说:错误”请帮助我。谢谢

0 个答案:

没有答案
相关问题