我一直在试验这个,试图了解页面生命周期几个小时。我完全被困在这一点上:'(任何帮助将非常感激在动态填充的CheckBoxList中预先选择项目
以下是我的方法我的_PrefillWizard
方法实际上适用于我的页面上的所有控件,除了那些动态填充的控件。CheckBoxList
s是这样的,因为它们是根据我的数据库中的表中的可选值自动生成的。我已经在我的标记中拥有此控件,因此...我如何在运行其他代码之前强制执行此操作并准备就绪?
<asp:CheckBoxList ID="MyLanguagesCBL" runat="server" RepeatDirection="Vertical"
RepeatColumns="4" Width="100%" DataSourceID="LanguagesSDS"
DataTextField="Language" DataValueField="ID">
</asp:CheckBoxList>
<asp:SqlDataSource ID="LanguagesSDS" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="select ID, [Language] from LanguagesListTable"
DataSourceMode="DataReader">
</asp:SqlDataSource>
显然,这些特定的控件尚未生成,或者在调用我的_PrefillWizard
时导致没有任何CheckBox被预先生成-填充。 如何在调用预填方法之前让它们生成?谢谢;)
事情发生的点击事件。
'On "Load" Button click, clears a Wizard control and Prefills it with the
' data from the clicked record based on the primary key stored in SessionState.
Protected Sub RowClick(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView2.RowCommand
If e.CommandName = "Select" Then
Session.Add("ClickedPrimaryKey", GridView2.DataKeys(e.CommandArgument).Value.ToString)
'This is the main function which calls "_SetCheckBoxes" among others.
_PrefillWizard(Session.Item("ClickedPrimaryKey"))
End If
End Sub
这是我来填充我的CheckBoxList
控制功能,但它显然取决于是否有已加载页面上的控制。
'Parse a CSV String from the Database back into CheckBoxList Selections
Protected Sub _SetCheckBoxes(ByRef cbl As CheckBoxList, ByRef dt As DataTable, ByVal row As Integer, ByVal csv As String)
'Do something if there is a value in the cell
If Not IsDBNull(dt.Rows.Find(row)(csv)) Then
For Each item As ListItem In cbl.Items
item.Selected = False 'Reset the checkbox first
'Then, if the ID value of the checkbox corresponds to a value
' in the CSV string, then tick the checkbox.
If csv.Contains(item.Value) Then
item.Selected = True
End If
Next
End If
End Sub
我迷路了。 :(目前我有一个预填充的按钮单击表单,在该表单上生成了我动态填充的CheckBoxList,我相当确定问题是事件以错误的顺序触发,而我不能为我的生活弄清楚如何让事情按照正确的顺序发生。:( – Chiramisu