DropDownList用DataSourceID绑定后,无法再手动添加项目
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="NAME" DataValueField="DEPTNAME"></asp:DropDownList>我想在程序再添加一个项目 DropDownList1.Items.Insert(0, new ListItem("aa"));
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="NAME" DataValueField="DEPTNAME"></asp:DropDownList>我想在程序再添加一个项目 DropDownList1.Items.Insert(0, new ListItem("aa"));
.....数据操作
DropDownList1.DataSource=dr;
DropDownList1.DataBind();
dr.Close();
if (DropDownList1.Items.Count==0)
{
DropDownList1.Items.Add(new ListItem("aa","0"));
}
else
{
DropDownList1.Items.Insert(0,new ListItem("aa","0"));
}
再加一句
DropDownList1.Items.Insert(0,new ListItem("aa","0"));