Asp.net 2.0 中    页面载入时自动选择一个下拉列表框的值?我把值传过去(下拉列表框绑定后有这个值),我希望页面载入时下拉列表框中能自动选择相应的项.

解决方案 »

  1.   


    // 假设这个值是传过来的
    string strDefault = "aaaa";
    if (this.DropDownList1.Items.FindByValue(strDefault) != null)
    {
         this.DropDownList1.ClearSelection();
         this.DropDownList1.Items.FindByValue(strDefault).Selected = true;
    }
      

  2.   

    Dim Item1 As ListItem
    For i As Short = 1 To 12
        Item1 = New ListItem(i, i)
        if item1.value="你传的值" then
           DropList.SelectedIndex = i 
           exit for
        End if
    Next
      

  3.   

    To:  minajo21(大眼睛)用你这方法后,我这里出现这种异常: 未将对象引用设置到对象的实例
    不知怎么办,望指点!
      

  4.   

    DropDownList1.Items.FindByValue(strDefault).Selected = true
      

  5.   

    To:  minajo21(大眼睛)我是先绑定后,再用你说的这个方法去做的, 结果会出现"未将对象引用设置到对象的实例"的异常.你这个方法应该是没问题的,你能不能给一个例子让我参考?