通过页面传值,在后台获取传过来的值,然后根据这个值在dropdownlist的下拉列表中找相同的,如果有就显示为当前值,没有就显示下拉列表的第一个。

解决方案 »

  1.   


                ListItem item = droplm.Items.FindByValue("传过来的值");
                if (item != null)
                    item.Selected = true;
      

  2.   


    try
    {
         string s = Request.QueryString["brand"];
         this.DropDownList1.Items.FindByText(s).Selected = true;
    }
    catch(Exception)
    {
    }
      

  3.   

    string val = Request.Form["YouVal"]; // 你表单里传递的值
    // 遍历DropdownList
    bool flag = false;
    foreach(ListItem li in dropdownlist1){
        if(li.Value == val){
            flag = true;
            break;
        }
    }
    // 没找到,设置val等于下拉列表第一个值
    if(!flag){
        val = dropdownlist1.Items[0].Value;
    }// val即你想要的结果
      

  4.   

    C# codestring val = Request.Form["YouVal"]; // 你表单里传递的值
    // 遍历DropdownList
    bool flag = false;
    foreach(ListItem li in dropdownlist1){
        if(li.Value == val){
            flag = true;
            break;
        }
    }
    // 没找到,设置val等于下拉列表第一个值
    if(!flag){
        val = dropdownlist1.Items[0].Value;
    }// val即你想要的结果
      

  5.   

    foreach遍历dropdownList{
       if(传过来的值 == 遍历中的一项)
       {
            dropdownlist.SelectedValue = 传过来的值;   
       }else{
            dropdownlist.SelectedValue = 默认为下拉列表第一个;
       }
    }只提供思路,自己找代码写写
      

  6.   

     ListItem item = droplm.Items.FindByValue("传过来的值");
      

  7.   

    if (this.DropDownList1.Items.FindByValue("10") != null)
            {
                this.DropDownList1.Items.FindByValue("10").Selected = true;
            }
            else
            {
                this.DropDownList1.SelectedValue = null;
                this.DropDownList1.Items[0].Selected = true;
            }那个10就是你取出来要比对的值
      

  8.   

    C# codestring val = Request.QueryString["YouVal"]; // 頁面傳的值
    // 遍历DropdownList的项值是否存在
    bool search= false;
    foreach(ListItem li in dropdownlist1){
      if(li.Value == val){
      search= true;
      break;
      }
    }
    // 没找设定第一项选中
    if(!search){
      dropdownlist1.Items[0].Selected=true;
    }