下拉列表不显示项目
本文关键字:项目 显示 下拉列表 | 更新日期: 2023-09-27 18:08:01
在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();
您没有分配DataSource
:
ddlchgstatus1.DataSource = ds.Tables[0];
ddlchgstatus1.DataTextField = "Name";
ddlchgstatus1.DataValueField = "StausID";
ddlchgstatus1.DataBind();