for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)  //ds1.Tables[0].Rows.Count 是dropdownlist2中有多少项
            {
                if(this.DropDownList2.)
                this.DropDownList2.Items.FindByText(ds.Tables[0].Rows[0]["YaoType_name"].ToString()).Selected = true;
            }那个if语句 中的判断语句怎么写怎么才能判断从索引0 一直判断到最后, 如果dropdownlist的Text值有匹配的的,就会执行里面的语句 if(this.DropDownList2.。=“某值”)

解决方案 »

  1.   

    for (int n = 0; n < DropDownList2.Items.Count; n++) 
      {
      if(this.DropDownList2.Items[n].Text=="匹配值")
          //do any thing..
      }
      

  2.   


     if(this.DropDownList2.SelectedItem.Text="某值")
      this.DropDownList2.Items.FindByText(ds.Tables[0].Rows[0]["YaoType_name"].ToString()).Selected = true;
      }
      

  3.   

    不需要用循环
    ListIlem li=this.DropDownList2.Items.FindByText(ds.Tables[0].Rows[0]["YaoType_name"].ToString());
    if(li!=null)
    {
       li.selected=true;
    }
      

  4.   

    DropDownList2.SelectedIndex = DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(ds.Tables[0].Rows[0]["YaoType_name"].ToString())); 
      

  5.   


    for (int n = 0; n < DropDownList2.Items.Count; n++) 
      {
      if(this.DropDownList2.Items[n].Text=="匹配值")
           {
                this.DropDownList2.Items.FindByText(ds.Tables[0].Rows[0]["YaoType_name"].ToString()).Selected = true;
           }
      }