dropdownlist1.selectedvalue有这个属性吗? If Not IsPostBack Then binddrplist() End IfSub binddrplist() con.Open() Dim cmd As New OleDbCommand("select par_id,cur_id from xj.treeview", con) Dim dr As OleDbDataReader dr = cmd.ExecuteReader DropDownList1.DataSource = dr DropDownList1.DataTextField = "cur_id" DropDownList1.DataValueField = "par_id" DropDownList1.DataBind() con.Close() End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged Label1.Text = DropDownList1.SelectedItem.Value End Sub
if(!IsPostBack)
{
//绑定的代码
}
中绑定了.
dropdownlist1.selectedvalue="USA";也可以选中USA这行.但是strCountry = dropdownlist1.selectedvalue;后
strCountry为空串这是为什么?
绑定的数据源是我在程序中创建的sqldatareader.
请问是用selectedvalue属性取值吗?还有没有其他取值方法.
dropdownlist1.SelectedItem.Text
dropdownlist1.SelectedItem.Text;
dropdownlist1.SelectedItem.Value;
If Not IsPostBack Then
binddrplist()
End IfSub binddrplist()
con.Open()
Dim cmd As New OleDbCommand("select par_id,cur_id from xj.treeview", con)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader
DropDownList1.DataSource = dr
DropDownList1.DataTextField = "cur_id"
DropDownList1.DataValueField = "par_id"
DropDownList1.DataBind()
con.Close()
End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Value
End Sub
使用DropDownList1.SelectedItem.Value出系统错误
system.nullreference.exception