2009-06-24 7 views
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 

答えて

2

ドロップダウンリストでAppendDataBoundItemsプロパティをtrueに設定しようとしましたか?

+0

これはうまくいきました。どうもありがとう! –

関連する問題