動的に作成されたドロップダウン リスト コントロールの selectedvalue プロパティが更新されないという問題があります。
コンボとその他のコントロールを含むタイプ ctlProductosFormatos のカスタム コントロールがあります。このカスタム コントロールを別の場所で動的に作成し、動的に作成されたコントロールのすべてのコンボを繰り返し処理して、別のダミー ドロップダウンリストから必要な値をコピーしてアイテム リストを更新します。
このコードのコントロールは正しく繰り返され、コンボも正しく埋められます。私の問題は、アイテムが更新される前と同じ値で各コンボの選択された値を維持したいということですが、これは失敗します。
コードにステップインして最初のコンボの反復のみを実行し、ループの外にジャンプすると、このコンボは正しく選択された値で埋められますが、完全なループを実行すると、すべてのコンボが同じ値で設定されます最後のコンボよりも値が大きいので、すべての反復で同じコントロールをインスタンス化するようなものに関連していると思いますが、私のコードではそうではないようです.
Dim ControlFormato As ctlProductosFormatos
' Iterates through custom controls collection, IEnumerable(Of ctlProductosFormatos)
For Each ControlFormato In Controles
' Get the dropdownlist inside the current custom control
Dim ControlComboFind As Control = ControlFormato.FindControl("cmbFotoFormato")
Dim ControlCombo As DropDownList = CType(ControlComboFind, DropDownList)
' Get the currently selected value in the dropdownlist
Dim ValorSeleccionado As String = ControlCombo.SelectedValue
' Clear the items in the current combo,and fills with the ones in a dummy combo
ControlCombo.Items.Clear()
ControlCombo.Items.AddRange(ComboPatron.Items.OfType(Of ListItem)().ToArray())
' Sets the current combo selected item with the previously saved one
ControlCombo.SelectedValue = ValorSeleccionado
Next