我的DropDownList 指定了 数据源 ;但我想在DDL的第一个选项加一个“——请选择——”
请各位帮帮忙!!
------解决方案--------------------------------------------------------
- C# code
            DataTable dt = new DataTable();            DropDownList1.DataSource = dt;//dt是SQL查询出来的DataTable,绑定数据源              DropDownList1.DataTextField = "字段";            DropDownList1.DataValueField = "字段";            DropDownList1.DataBind();            DropDownList1.Items.Insert(0, new ListItem("——请选择——", "0"));//插入项
------解决方案--------------------------------------------------------
this.ddl.Items.Insert(0,new ListItem("--请选择---","-1"));
------解决方案--------------------------------------------------------
- C# code
this.DropDownList1.Items.Insert(0, new ListItem("-请选择-", "0"));
------解决方案--------------------------------------------------------
如果不是写代码的话,不是很好做!
要自己写代码指定DropDownList 的数据源,不过在指定之前必须对数据加工
如Categorie 是一个类
CategotyBLL是三成中的一个类
  public void GetDropDownListData()
   {
       IList<Categorie> list = CategotyBLL.GetAll();//重数据库中获得数据放在IList中, IList中都放的是类的实例
//new一个类,把它放到IList中
       Categorie cate = new Categorie();
       cate.Name = "--选择--";
       cate.Id = -1;
    
       list.Insert(0, cate);
//在将IList的对象和DropDownList1绑定
       this.DropDownList1.DataSource = list;
       this.DropDownList1.DataTextField = "Name";
       this.DropDownList1.DataValueField = "Id";
       this.DropDownList1.DataBind();
   }
------解决方案--------------------------------------------------------
DropDownList1.Items.Insert(0, new ListItem("——请选择——", "0"));//
------解决方案--------------------------------------------------------