如果直接绑定数据库的话,那么显示的全是数据。我想在第一项中加个“全部”的字段项,有没有个简单的方法?

解决方案 »

  1.   

    绑定后再Page_Load中写
    if(!IsPostBack)
    {
      DropDownList1.Items.Add("全部",0);
    }然后再DropDownList的SelectedIndexChanged事件中为此“全部”做处理(value 0);
      

  2.   

    dropdownlist.Items.Insert(0,new   ListItem( "全部", "-1 "));
      

  3.   

          
    if (!Page.IsPostBack)
            {
               //数据绑定
               this.控件ID.Items.Insert(0, new ListItem("全部", "-1"));
           }
      

  4.   

    DropDownList1.DataSource=datatable;
    DropDownList1.value="id";
    DropDownList1.Text="name";
    DropDownList1.DataBind();
    DropDownList1.Items.Insert(0, "全部");
      

  5.   


    //........
    DropDownList1.DataBind();
    //以上是DropDownList1直接绑定数据库代码
    //以下就是你需要的效果
    DropDownList1.SelectedIndex = -1;
    ListItem list1 = new ListItem();
    list1.Text = "全部";
    list1.Value = "-1";
    list1.Selected = true;
    DropDownList1.Items.Insert(0,list1);
      

  6.   

     this.DropDownList1.Items.Insert(0, new ListItem("全部", "0"));
      

  7.   

    动态绑定,开始插入this.DropDownList1.Items.Insert(0, new ListItem("全部", "0"));
    后面的你自己插入,注意后面的值域要不一样