我的页面里放了一个DropDownList,是用数据绑定的,我想给DropDownList添加一个用户未选择项,不知如何添加。我的DropDownList数据是这样绑定的:
DataTable xf = tbmyclass.szfh_username();
this.DropDownList9.DataSource = xf;
this.DropDownList9.DataTextField = xf.Columns["szfh"].ColumnName;
this.DropDownList9.DataValueField = xf.Columns["szfh"].ColumnName;
this.DropDownList9.DataBind();
这样可以绑定数据,但是不知道如何在添加一个用户未选择项,本人是新手,希望高手指点一下,谢谢。
DataTable xf = tbmyclass.szfh_username();
this.DropDownList9.DataSource = xf;
this.DropDownList9.DataTextField = xf.Columns["szfh"].ColumnName;
this.DropDownList9.DataValueField = xf.Columns["szfh"].ColumnName;
this.DropDownList9.DataBind();
这样可以绑定数据,但是不知道如何在添加一个用户未选择项,本人是新手,希望高手指点一下,谢谢。
ListItem item = new ListItem("未选择");
DropDownList1.Items.Add(item);
DataRow dr = xf.NewRow();
dr["szfh"] = "未选择";
xf.Rows.InsertAt(dr,0);
大致是这样自己试验一下
ddlist.DataSource=ds;
ddlist.DataValueField="id";
ddlist.DataTextField="name";
ddlist.DataBind();
ddlist.Items.Insert(0,new ListItem("==请选择==",""));
谢谢,按照FlashElf的方法解决了,非常感谢FlashElf,也非常感谢您关注我的问题。