不好意思,写错一个字:是静态值,不是“表态值”。
我是这样做的:(page_load里有它的绑定数据)
<asp:dropdownlist 
id = "asearch" 
 runat = "server">
<asp:ListItem >sfsfd</asp:listItem>
</asp:dropdownlist>但这样不行,怎么回事?

解决方案 »

  1.   

    你可以绑定dropdownlist后,在用dropdownlist.items.insert方法添加
      

  2.   

    ......绑定或添加dropdownlist1的代码DropDownList1.Items.Insert(0,"%");
      

  3.   

    private void adddatatodropdownlist1()
    {
       string connstring="data source=mbm;initial catalog=kmsdb;user id=mbm;password=mbm";
       string querystring="select distinct cDepartmentname from t_Department";
      SqlConnection myconn=new SqlConnection(connstring);
      myconn.Open();
      SqlDataAdapter myadapter=new SqlDataAdapter(querystring,myconn);
      DataSet ds=new DataSet();
      myadapter.Fill(ds,"t_Department");
      myconn.Close();
      DropDownList1.DataSource=ds.Tables[0].DefaultView;
      DropDownList1.DataTextField=ds.Tables["t_Department"].Columns["cDepartmentName"].ToString();
      DropDownList1.DataBind();DropDownList1.Items.Insert(0,"%");//静态的,这行以上是从数据库表绑定的
    }
      

  4.   

    谢谢,动态插入一个Item已经可以啦!可又怎样将它放至最顶的一项呢?或者说让它作为默认选项的属性是什么呢?嘿,楼上的同行:hy_david
    你是怎样强加一个表态值的?请教!
    谢谢!
      

  5.   

    DropDownList1.Items.Insert(0,"%");
    0是索引值,表示插入到最顶
    然后在
    DropDownList1.Items[0].Selected=true;//默认选择第一行
      

  6.   

    非常谢谢楼上的。
    那怎样设置它的Value呢?
      

  7.   

    DropDownList1.Items[0].Value=你想要得值
      

  8.   

    是这样的,如上方法所设置的VALUE 和 text 是一样的。
    若要两者不一样呢?
      

  9.   

    private void adddatatodropdownlist1()
    {
       string connstring="data source=mbm;initial catalog=kmsdb;user id=mbm;password=mbm";
       string querystring="select distinct cDepartmentname from t_Department";
      SqlConnection myconn=new SqlConnection(connstring);
      myconn.Open();
      SqlDataAdapter myadapter=new SqlDataAdapter(querystring,myconn);
      DataSet ds=new DataSet();
      myadapter.Fill(ds,"t_Department");
      myconn.Close();
      DropDownList1.DataSource=ds.Tables[0].DefaultView;
      DropDownList1.DataTextField=ds.Tables["t_Department"].Columns["cDepartmentName"].ToString();
      DropDownList1.DataBind();DropDownList1.Items.Insert(0,"%");//静态的,这行以上是从数据库表绑定的DropDownList1.Items[0].Value="111";//赋值给value,现在Text属性是%,而value属性是111,明白了就给点分吧

      

  10.   

    OK,已经好啦!我用的是VB,告诉VB用户,上面一句应该是:
    DropDownList1.Items(0).Value="111"   ‘用小括号
    一束“鲜花”送给mbm(-- (@ \/ @) --)   ∞      ∞      ∞          Ω      Ω        
      ∞∞∞    ∞  ∞      ΩΩΩΩΩΩΩΩΩΩΩ  
    ∞    ∞  ∞∞∞∞∞∞        Ω      Ω        
    ∞∞∞∞∞      ∞                              
    ∞  ∞  ∞      ∞            Ω    Ω          
    ∞∞∞∞∞  ∞∞∞∞∞      Ω      Ω    Ω    
    ∞  ∞  ∞      ∞        ΩΩ      Ω  Ω      
    ∞∞∞∞∞∞∞∞∞∞∞  Ω  Ω      ΩΩ        
                    ∞          Ω  ΩΩΩ      Ω  
        ∞∞∞      ∞          Ω      Ω      Ω  
    ∞∞            ∞          Ω      ΩΩΩΩΩ