如果ListBox和DropDownList绑定的静态数据是没有问题的,如果绑定的是动态数据源(SqlDataReader)时,我遇到了如下问题:ListBox和DropDownList都能正常的显示数据项(绑定SqlDataReader成功),但是当我要取其中的ListItem值的时候,比如string name=ListBox/DropDownList.SelectItem.Text时,ListBox.SelectItem.Text始终为空;DropDownList.SelectItem.Text始终等于selectindex==0时的值,急我呀!用不用Page.IsPostBack?我用了也不行!怎么会这样?

解决方案 »

  1.   

    Dim publishertype As New OleDbDataAdapter("select Publisher_Id,Publisher_Name from T_Book_Publisher order by Publisher_Name asc", Conn)
                    Dim pubds As New DataSet
                    publishertype.Fill(pubds, "T_Book_Publisher")
                    Me.DropDownList3.DataSource = pubds.Tables("T_Book_Publisher").DefaultView
                    Me.DropDownList3.DataMember = "T_Book_Publisher"
                    Me.DropDownList3.DataTextField = "Publisher_Name"
                    Me.DropDownList3.DataValueField = "Publisher_Id"
                    Me.DropDownList3.DataBind()
    看看效果
      

  2.   

    if(!IsPostBack)
    {}
    一般用SelectedValue!
      

  3.   

    if(!IsPostBack)
    {
       string name=ListBox/DropDownList.SelectItem.Text;
    }
      

  4.   

    遇到这种情况首先要单步调试一下,要知道高开发不可以心急哦.我的判断是没有使用if(!this.IsPostBack){}我是个菜鸟,刚开始编程的时候也遇到你说的这个问题.
      

  5.   

    哎,该不会是DropDownList1.DataSource 不能绑定SqlDataReader数据源吧???????????????
      

  6.   

    单步调试一下,看绑定的语句是否包含于if(!Page.IsPostBack)中了.
      

  7.   

    肯定是page_load()是又重新加載了數據庫綁定,把選擇的值又給復蓋了。
    If Not IsPostBack Then
     BindData() '自定義綁定的函數,2樓的就是。
    End if