我想在添加数据绑定后添加“请选择”项目到我的下拉列表但它似乎不起作用。这就是我想要的,
ddlListMine.Items.Add(new ListItem("Please Please Please Select....", "-1"));
ddlListMine.DataSource = GetSomeChickens();
ddListMine.DataTextField = "ChickenName";
ddListMine.DataValueField= "NumberOfEggsChickenLay";
ddListMine.DataBind();
我也尝试将第一行代码移动到最后,但随后“请取悦......”项目出现在下拉列表的末尾。
答案 0 :(得分:1)
在Oth Index
插入您的项目 ddlListMine.DataSource = GetSomeChickens();
ddListMine.DataTextField = "ChickenName";
ddListMine.DataValueField= "NumberOfEggsChickenLay";
ddListMine.Items.Insert(0, new ListItem("Please Please Please Select....", "0"));
ddListMine.DataBind();
答案 1 :(得分:0)
试试这个,先绑定你的datalist,然后将空值listitem设置为选中。
ddlListMine.DataSource = GetSomeChickens();
ddListMine.DataTextField = "ChickenName";
ddListMine.DataValueField= "NumberOfEggsChickenLay";
ddListMine.DataBind();
ddlListMine.Items.Insert(0, new ListItem("Select Category", String.Empty));
ddListMine.SelectedIndex = 0;