我正在使用UpdatePanel和Ajax Tabcontainer。我有一个项目模板列,其中包含checkbox和radiobutton。基于一种类型的场,它们中的任何一个都是可见的。
<asp:GridView ID="gvAutoMatchFund" runat="server" AutoGenerateColumns="False" ClientIDMode="Static"
AllowPaging="True" PageSize="50" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
OnRowDataBound="gvAutoMatchFund_RowDataBound" BorderWidth="1px" CellPadding="3"
onpageindexchanging="gvAutoMatchFund_PageIndexChanging"
Width="100%">
<Columns>
<asp:BoundField DataField="DYNAMO_FUNDNAME" HeaderText="Dynamo Fund Name" ItemStyle-Width="25%" />
<asp:BoundField DataField="DYNAMO_FUNDID" HeaderText="Dynamo Fund ID" ItemStyle-Width="25%" />
<asp:BoundField DataField="INVESTRAN_FUNDNAME" HeaderText="Investran Fund Name" ItemStyle-Width="25%" />
<asp:BoundField DataField="INVESTRAN_SYSTEMFUNDID" HeaderText="Inv. Sys. Fund ID" />
<asp:TemplateField ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:CheckBox ID="chkSelAll" Text="Select" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSel" runat="server" Visible='<%#(!(bool)Eval("ISMULTIPLE"))%>' />
<asp:RadioButton ID="rdoSel" runat="server" Visible='<%#((bool)Eval("ISMULTIPLE"))%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#C6E5F5" Font-Bold="True" ForeColor="#4695BD" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
<EmptyDataRowStyle ForeColor="Maroon" />
</asp:GridView>
我在检查回发后填充它
if (!Page.IsPostBack)
{
...
PopulateMyGV();
}
当单击一个按钮时,我试图循环遍历此gridview中的每个项目,并使用FindControl方法查找复选框和单选按钮。到目前为止是有效的,但是即使选中了radiobutton,它仍然是假的。但是,如果选中或不选中复选框工作正常(为已检查属性提供正确的值)。见下面的代码
在按钮中单击
foreach (GridViewRow gvr in gvAutoMatchFund.Rows)
{
CheckBox chkSel = (CheckBox)gvr.FindControl("chkSel");
RadioButton rdoSel = (RadioButton)gvr.FindControl("rdoSel");
if (chkSel != null)
{
if (chkSel.Checked)
{
...
}
}
if (rdoSel != null)
{
if (rdoSel.Checked)
{
...
}
}
}
我错过了什么?
答案 0 :(得分:0)
花了很多时间后,我们终于发现这种奇怪的行为是因为我们在RowDataBound事件中以编程方式更改了单选按钮的ID。请参阅下面的代码。
protected void gvAutoMatchFund_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
USP_MDM_SUGGESTED_AUTOMATCH_FUNDResult objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult = (USP_MDM_SUGGESTED_AUTOMATCH_FUNDResult)e.Row.DataItem;
RadioButton rdoSel = (RadioButton)e.Row.FindControl("rdoSel");
rdoSel.ID = "rdoSel_" + objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult.DYNAMO_FUNDID
+ "_" + objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult.INVESTRAN_SYSTEMFUNDID
+ "_" + objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult.INVESTRAN_FUNDID;
}
}
所以我删除了上面的逻辑并使用了以下逻辑来传递各种参数以及radiobutton
protected void gvAutoMatchFund_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
USP_MDM_SUGGESTED_AUTOMATCH_FUNDResult objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult = (USP_MDM_SUGGESTED_AUTOMATCH_FUNDResult)e.Row.DataItem;
RadioButton rdoSel = (RadioButton)e.Row.FindControl("rdoSel");
string sValue = "rdoSel_" + objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult.DYNAMO_FUNDID
+ "_" + objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult.INVESTRAN_SYSTEMFUNDID
+ "_" + objUSP_MDM_SUGGESTED_AUTOMATCH_FUNDResult.INVESTRAN_FUNDID;
rdoSel.Attributes.Add("value", sValue);
}
}
这解决了我上面描述的两个问题。