比如在a.aspx中有已绑定了的DropDownList控件
请问如何定义它初始选定的值?比如先选择了“北京市”,当点击提交后,网页链接到了a.aspx?key=1,DropDownList的选定值就是“北京市”,而不是“请选择城市”

解决方案 »

  1.   

    Public Function Getdrop(ByVal Thedrop As DropDownlist, ByVal str As String)  '绑定DropDownList,返回index值
            Dim i As Integer
            For i = 0 To CInt(Thedrop.Items.Count - 1)
                If Thedrop.Items(i).Text = str Then
                    Thedrop.SelectedIndex = i
                End If
            Next
        End Function给你这个,偶一直在用的!!
      

  2.   

    你在绑定之后,判断参数,根据参数修改其的值,例如:
    把ID作为DropDownList的ValueMember的话yourDropDownList.Items.FindByValue( "1" ).Selected = true;
      

  3.   

    用法:
    Getdrop(你的dropdownlist,"北京市")
      

  4.   

    for(int i = 0; i <DropDownlist.Items.Count - 1; i++)
    {
       if (DropDownlist.Items(i).Text == name )//name 为你前端传来的值“北京”
          {
            DropDownlist.SelectedIndex  = i;     
          }
    }