这就不对了,我用了两种方法分别测试了200个和1000个元素,照样正常呀 下面是我的测试程序(vb.net),很容易看懂,请确定你的程序是否正确 注意:1。你数据绑定 是否在 if(!(IsPostBack)){}内 2。你的dropdownlist 是否 autopostback=true ①测试200个元素(dropdownlist直接添加元素的方法) Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 If Not IsPostBack Then Dim i As Integer For i = 0 To 200 Dim item As New ListItem() item.Text = i item.Value = i DropDownList1.Items.Add(item) Next End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged TextBox1.Text = DropDownList1.SelectedItem.Text + "**" + DropDownList1.SelectedItem.Value End Sub②测试1000个元素(数据绑定方法) Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 If Not IsPostBack Then Dim t As New DataTable() t.Columns.Add("Txt", GetType(String)) t.Columns.Add("Val", GetType(Integer)) Dim i As Integer For i = 0 To 1000 Dim r As DataRow = t.NewRow r("Txt") = i.ToString r("Val") = i t.Rows.Add(r) Next DropDownList1.DataSource = t DropDownList1.DataTextField = "Txt" DropDownList1.DataValueField = "Val" DropDownList1.DataBind() End If End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged TextBox1.Text = DropDownList1.SelectedItem.Text + "**" + DropDownList1.SelectedItem.Value End Sub
DDL_DropDownList.options[DDL_DropDownList.selectedIndex].text
DDL_DropDownList.options[DDL_DropDownList.selectedIndex].value
如果相同会出错
细分
分成多级
一个DDL里面放这么多数据
选择的时候要找半天呢。
很累的
你绑定ddl的代码是否被多次执行?比如放在page_load事件里面又没有判断ispostback或者ddl是否已经存在数据?我现在的ddl已经有50条记录,没有问题。见到这个帖子之后我又添加了100条,仍然没有问题
下面是我的测试程序(vb.net),很容易看懂,请确定你的程序是否正确
注意:1。你数据绑定 是否在 if(!(IsPostBack)){}内
2。你的dropdownlist 是否 autopostback=true
①测试200个元素(dropdownlist直接添加元素的方法)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Dim i As Integer
For i = 0 To 200
Dim item As New ListItem()
item.Text = i
item.Value = i
DropDownList1.Items.Add(item)
Next
End If
End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
TextBox1.Text = DropDownList1.SelectedItem.Text + "**" + DropDownList1.SelectedItem.Value
End Sub②测试1000个元素(数据绑定方法)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Dim t As New DataTable()
t.Columns.Add("Txt", GetType(String))
t.Columns.Add("Val", GetType(Integer))
Dim i As Integer
For i = 0 To 1000
Dim r As DataRow = t.NewRow
r("Txt") = i.ToString
r("Val") = i
t.Rows.Add(r)
Next
DropDownList1.DataSource = t
DropDownList1.DataTextField = "Txt"
DropDownList1.DataValueField = "Val"
DropDownList1.DataBind() End If
End Sub Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
TextBox1.Text = DropDownList1.SelectedItem.Text + "**" + DropDownList1.SelectedItem.Value
End Sub