我正尝试在下拉列表的开头添加一个ListItem。我不知道为什么这个代码不能工作。它只添加数据库信息。为了定制我自己的下拉列表,我创建了一个继承自dropdownlist的类。
public class MyDropDownList : DropDownList
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.BindItems();
}
private void BindItems()
{
this.Items.Clear();
this.DataSource = this.GetData();
this.DataValueField = "CompositePK";
this.DataTextField = "Description";
this.DataBind();
this.Items.Insert(0, new ListItem("-Select-", "-1"));
}
}发布于 2015-01-23 23:28:15
您必须插入一个新的ListItem:
this.Items.Insert(0, new ListItem("", "-Select-"));https://stackoverflow.com/questions/28113148
复制相似问题