我想遍历radiobutton,先都设置为未选中,然后选中某一个,因为启用了分页,如果总数据3条的话,每页显示2条的情况下,我选中第一页的rb时gvSelectSection.Rows.Count为2,我选中第二页的rb时gvSelectSection.Rows.Count为1。不启用分页gvSelectSection.Rows.Count就是3没问题的。为什么一分页count就只是当前页数的count了,我想遍历所有页的rb时该怎么写?? for (int i = 0; i < gvSelectSection.Rows.Count; i++)
{
RadioButton rb = (RadioButton)gvSelectSection.Rows[i].FindControl("rbSelectSection");
rb.Checked = false;
}
for (int i = 0; i < gvSelectSection.Rows.Count; i++)
{
RadioButton rb = (RadioButton)gvSelectSection.Rows[i].FindControl("rbSelectSection");
if (rb == (RadioButton)sender)
{
rb.Checked = false;
}
<asp:GridView ID="gvSelectSection" runat="server" AutoGenerateColumns="False" AllowPaging="true"
DataSourceID="odsSelectSection" BackColor="White" BorderColor="#E7E7FF" BorderStyle="Outset"
BorderWidth="2px" CellPadding="3" GridLines="Horizontal" PageSize="2"
Font-Size="Small" DataKeyNames="SectionID">
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbSelectSection" runat="server" AutoPostBack="true"
oncheckedchanged="RbSelectSection_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SectionSN" HeaderText="标段" SortExpression="SectionSN" />
<asp:BoundField DataField="ContractScale" HeaderText="造价" SortExpression="ContractScale" />
<asp:BoundField DataField="ScaleArea" HeaderText="面积" SortExpression="ScaleArea" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
{
RadioButton rb = (RadioButton)gvSelectSection.Rows[i].FindControl("rbSelectSection");
rb.Checked = false;
}
for (int i = 0; i < gvSelectSection.Rows.Count; i++)
{
RadioButton rb = (RadioButton)gvSelectSection.Rows[i].FindControl("rbSelectSection");
if (rb == (RadioButton)sender)
{
rb.Checked = false;
}
<asp:GridView ID="gvSelectSection" runat="server" AutoGenerateColumns="False" AllowPaging="true"
DataSourceID="odsSelectSection" BackColor="White" BorderColor="#E7E7FF" BorderStyle="Outset"
BorderWidth="2px" CellPadding="3" GridLines="Horizontal" PageSize="2"
Font-Size="Small" DataKeyNames="SectionID">
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbSelectSection" runat="server" AutoPostBack="true"
oncheckedchanged="RbSelectSection_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SectionSN" HeaderText="标段" SortExpression="SectionSN" />
<asp:BoundField DataField="ContractScale" HeaderText="造价" SortExpression="ContractScale" />
<asp:BoundField DataField="ScaleArea" HeaderText="面积" SortExpression="ScaleArea" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货