DropDownList判断值是否存在下拉列表中

 //1.值是text
      string aa=  Request.QueryString["CallReason"].ToString();//获取传值
      if (DropDownList1.Items.Contains(new ListItem(aa)))
      {
          DropDownList1.SelectedValue = aa;//如果存在则等于存在的值
      }
      else
      {
          DropDownList1.Items.Insert(0, new ListItem(aa, ""));//否则新增这个选项并且为选中值
          DropDownList1.DataBind();
      }

        //2.假如值是value
        //那么 int i = comboBox1.Items.IndexOf(value);
        //如果 i>=0则在下拉中,否在不在。

 

posted @ 2016-07-29 10:57  饮水思源^0^  阅读(720)  评论(0编辑  收藏  举报