如何设置DropDownList的默认选项为数据库内容的?例如:DropDownList有三项,分别为:初级,中级,高级(注:这三项的直接定义的,不是数据库中的);
    现在有一条记录为中级,在前台修改的时候如何把“中级”赋给DropDownList的默认值?

解决方案 »

  1.   

    if(DropDownList.FindByText("中级")!=null)
    {
        DropDownList.SelectedValue="中级选项的value";
    }
      

  2.   

    错了,应该是这样
    if(DropDownList.Items.FindByText("中级")!=null) 

        DropDownList.SelectedValue="中级选项的value"; 
    }
      

  3.   

    <asp:ListItem Value="初级" >初级</asp:ListItem>
    <asp:ListItem Value="中级" Selected="True>中级</asp:ListItem>
    <asp:ListItem Value="高级" >高级</asp:ListItem>
      

  4.   

    谢谢wggygah5,那个RadioButtonList是不是跟这个原理一样啊?
      

  5.   

    <asp:ListItem   Value="初级"   > 初级 </asp:ListItem> 
    <asp:ListItem   Value="中级"   > 中级 </asp:ListItem> 
    <asp:ListItem   Value="高级"   > 高级 </asp:ListItem> 
    DropDownList1.Items.FindByText("中级").Selected = true;
      

  6.   

    public void DataBind_dp(string id)
    {
    foreach (ListItem item in this.DropDownList1.Items)
    {
    if(item.Value.ToString().Equals(id))
    {
    item.Selected=true;
    break;
    }
    }
    }DataBind_dp("中级");这样行么?我弄了半天没弄出来!!
      

  7.   

    public   void   DataBind_dp(string id) 

       if(DropDownList.Items.FindByText(id)!=null)   
       {   
           DropDownList.SelectedValue=id;
       }
    } DataBind_dp("中级"); 
    这样是可以的,不过前提是你的DropDownList的“中级”选项的Text和Value都是“中级”