Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            If Request.Cookies("classes") Is Nothing Then
            Else
                If Request.Cookies("classes").Value = "Admin" Then
                     DropDownList1.Items.Add("Admin")
                     DropDownList1.Items.Add("Doctor")
                    DropDownList1.Items.Add(New ListItem("Admins", "Admins"))
                    DropDownList1.DataBind()
                ElseIf Request.Cookies("classes").Value = "Doctor" Then
                    DropDownList1.Items.Add("Custom")
                    DropDownList1.DataBind()
                Else
                    Response.Redirect("error/error.aspx")
                End If            End If
        End If
        '在此处放置初始化页的用户代码
    End Sub

解决方案 »

  1.   

    两行 DropDownList1.DataBind() 都可以去掉,lz这是直接加选项,不叫绑定;dim dt as DataTable
    dropdownlist1.Datasource = dt
    dropdownlist1.DataBind()
    上面这样绑定到某个数据源才需要DataBind()如果是绑定到某个数据源后还要添加一些item,那么dropdownlist1.Items.Add应该跟在DataBind后面
      

  2.   

    我把DATABIND去掉后.我前面的怎么还是没啊 ??
      就是                     DropDownList1.Items.Add("Admin")
                         DropDownList1.Items.Add("Doctor")
    这些好象没用啊....怎么回事/
      

  3.   

    DropDownList1.Items.Add("Admin")这样写理论上也是可以的,这样该item的value和text两个属性都是“Admin”
    但是既然lz说不行,那就改为DropDownList1.Items.Add(New ListItem("Admins", "Admins"))好了~