DropDownList中在数据绑定后插入第一项提示的方法
Links link = new Links();
SqlDataReader dr = null; dr = link.GetLinks(); DropDownList1.DataSource = dr; DropDownList1.DataTextField = "LinkName"; DropDownList1.DataValueField = "LinkID"; DropDownList1.DataBind();ListItem al = new ListItem("<--选择一个-->", "0");
al.Selected = true; DropDownList1.Items.Insert(0, al);其中Link是我写的一个类,返回的是一个 DataReader,其中LinkName还有LinkID各自绑定。
在绑定后,我希望在DropDownList第一个被选择的是提示<--选择一个-->那么就用
上面的方法Items.Insert来解决