如果ListBox和DropDownList绑定的静态数据是没有问题的,如果绑定的是动态数据源(SqlDataReader)时,我遇到了如下问题:ListBox和DropDownList都能正常的显示数据项(绑定SqlDataReader成功),但是当我要取其中的ListItem值的时候,比如string name=ListBox/DropDownList.SelectItem.Text时,ListBox.SelectItem.Text始终为空;DropDownList.SelectItem.Text始终等于selectindex==0时的值,急我呀!用不用Page.IsPostBack?我用了也不行!怎么会这样?
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()
看看效果
{}
一般用SelectedValue!
{
string name=ListBox/DropDownList.SelectItem.Text;
}
If Not IsPostBack Then
BindData() '自定義綁定的函數,2樓的就是。
End if