下拉列表没有显示项目

时间:2015-08-14 13:18:59

标签: c# asp.net

dataset中获取数据,items

中无法看到dropdownlist

ASPX

 <asp:DropDownList ID="ddlchgstatus1" runat="server" />

aspx.cs

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ShoppingConnectionString"].ConnectionString);    
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("select * from tbl_status", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
ddlchgstatus1.DataTextField = "Name";
ddlchgstatus1.DataValueField = "StausID";
ddlchgstatus1.DataBind();

1 个答案:

答案 0 :(得分:4)

您还没有分配DataSource

ddlchgstatus1.DataSource = ds.Tables[0];
ddlchgstatus1.DataTextField = "Name";
ddlchgstatus1.DataValueField = "StausID";
ddlchgstatus1.DataBind();