我有一个如下所示的DataGrid:
<asp:datagrid id="dgICDCodes" runat="server" bodyHeight="300px" CssClass="tblScroll" Width="100%">
<Columns>
<asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="clsGridHeaderText"
HeaderStyle-Wrap="False" HeaderStyle-Width="10%" ItemStyle-Width="10%">
<HeaderTemplate>
Select
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButton ID="rbSelect" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Code") %>'
AutoPostBack="true" />
</ItemTemplate>
<HeaderStyle Wrap="False" CssClass="clsGridHeaderText" Width="10%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
在代码隐藏中使用RB的Text
属性来设置一个变量,用于在用户选择该行时跟踪该行的唯一Code
。
用户输入搜索参数后,应用程序会构建列并使用数据库中的结果填充此网格。
当用户选择一行时,会发生这种情况:
IsPostBack
是true
某处此单选按钮的已检查状态是丢失或“重写”,但我绝对无法弄清楚在哪里,我想知道它是否与回发性质有关?但是,如果我删除AutoPostBack="true"
,则单选按钮的行为与预期的不同,并且可以在网格中选择多行。
Web开发新手,所以我真的不知道该怎么做......
编辑添加一些与Page_Load相关的代码:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Call mfpEnableDisableControls()
cmdSearch.Attributes.Add("onClick", "return mfpValidate();")
txtNoOfRecords.Attributes.Add("onBlur", "return mfpIsNoOfRecords(this);")
Call mfpFillPresumptiveRuleCombo()
mfpFillTierCombo()
cmdRefresh.Attributes.Add("onClick", "return mfpIsNoOfRecords(document.forms[0].txtNoOfRecords, true);")
mInitializeSpread(dgCodes, False, True, True)
mInitializeSpread(dgCodes_AdditionalTier, False, True)
mInitializeSpread(dgCodes_AdditionalCompliance, False, True)
Call mfpLoadData("-1", vbNullString, vbNullString, vbNullString)
`mfpLoadData executes some stored procedures, puts the results into the DataTables used in mfpBindGrid, and then it calls mfpBindGrid
Else
If Request("__EVENTTARGET").StartsWith(dgCodes.Controls(0).Controls(0).UniqueID.Replace("$", ":") & ":") = False Then
Call mfpBindGrid(False)
End If
End If
End Sub
mfpBindGrid
:
Private Sub mfpBindGrid(ByVal aBlnReloadFromDB As Boolean, Optional ByVal aCurrentPageIndex As Integer = 0)
mfpFindRadioButton(dgCodes.Controls) 'This just checks which RB was selected and stores a Code in a variable on the form
mfpInitGridColumns() 'This drops everything after the first column (the RB) and re-adds them
mFillGridData(mobjDTCodes, dgCodes, Not aBlnReloadFromDB, ViewState, aCurrentPageIndex)
mFillGridData(mobjDTTierCodes, dgCodes_AdditionalTier, Not aBlnReloadFromDB, ViewState, aCurrentPageIndex)
mFillGridData(mobjDTPeerCodes, dgCodes_AdditionalCompliance, Not aBlnReloadFromDB, ViewState, aCurrentPageIndex)
'These methods configure the grids (dgName) based on the DataTable (mobjDTname) and re-set their DataSource to the tables passed.
End Sub
这有点像clusterfsck。基本上是操作顺序:
页面加载 - &gt;不回发 - &gt; mfpLoadData() - &gt; BindGrid()
用户点击搜索 - &gt; PageLoad - &gt;回帖 - &gt; BindGrid() - &gt;搜索点击事件火灾 - &gt; mfpLoadData() - &gt; BindGrid()
用户选择行 - &gt; PageLoad - &gt;回帖 - &gt; BindGrid()
也许这是我缺乏web开发经验,但这似乎是一个巨大的混乱,某些地方可能不需要做。