0
我想添加一个项目到一个Setter中的DropDownList,并且添加的项目不保留。不能将项目添加到SetDepter属性中的DropDownList
我已经证实,ViewState是正确启用在这个问题(Switched to ASP.NET 3.5, DropDownList doesn't remember dynamically added items)
这里是我的代码提示。
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If ddlCountry.Items.Count < Country.GetList.Length Then
ddlCountry.DataSource = Country.GetList()
ddlCountry.DataBind()
'At this point, there are correctly 231 items in ddlCountry.'
End If
End Sub
Public WriteOnly Property Country() As String
Set(ByVal Value As String)
If ddlCountry.Items.FindByValue(Value.Country) Is Nothing Then
Dim li As New ListItem(Value.Country, Value.Country)
ddlCountry.Items.Insert(0, li)
ddlCountry.SelectedIndex = ddlCountry.Items.IndexOf(li)
'At this point, there are correctly 232 items in ddlCountry'
Else
ddlCountry.SelectedValue = Value.Country
End If
End Set
End Property
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
If ddlCountry.Items.FindByText("<-- Please Select-->") Is Nothing Then
'At this point, we are incorrectly'
'back to 231 items - this is the problem.'
ddlCountry.Items.Insert(0, New ListItem("<-- Please Select-->", ""))
End If
End Sub
这工作 - 我从来没有遇到过这个属性。非常感谢! – 2009-06-24 09:26:25