在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();
答案 0 :(得分:4)
您还没有分配DataSource
:
ddlchgstatus1.DataSource = ds.Tables[0];
ddlchgstatus1.DataTextField = "Name";
ddlchgstatus1.DataValueField = "StausID";
ddlchgstatus1.DataBind();