0
Setter의 DropDownList에 항목을 추가하려고하는데 추가 된 항목이 유지되지 않습니다.ASP .NET의 Setter 속성에서 DropDownList에 항목을 추가 할 수 없습니다.
이 질문 (Switched to ASP.NET 3.5, DropDownList doesn't remember dynamically added items) 여기
내 코드는에 제안 viewstate가 올바르게 설정되어 있는지 확인했다.
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
그게 효과가 있었어요. 나는 그 재산을 결코 보지 못했습니다. 많은 감사합니다! –