I have a GridView
that contains a list of items with a checkbox
and I use the code below to "page" the table:
$(".gvdatatable").dataTable();
The problem occurs when I check which checkboxes
are selected, as it is currently only listed to those that are being displayed on the screen, that is, if I select two items from page 1 and select an item on page 2, the code only considers checkbox
selected from page 2. The interesting thing is that if I go back to page 1 checkbox
is still selected. Code GridView
:
<asp:GridView ID="dataTables" CssClass="gvdatatable table table-striped table-bordered table-hover textTable" runat="server"
AutoPostBack="True"
OnRowDataBound="Grid_RowDataBound"
OnPreRender="dataTables_PreRender">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckTodos" runat="server" onclick="GridSelectAllColumn(this);"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckStatus" runat="server" CssClass="chk" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NOME" HeaderText="NOME"/>
<asp:BoundField DataField="CPF" HeaderText="CPF" />
<asp:BoundField DataField="DATANASCIMENTO" HeaderText="DATA NASCIMENTO" />
</Columns>
Code that retrieves checkbox
:
foreach (GridViewRow viewRow in dataTables.Rows)
{
var t = viewRow.Cells[0].FindControl("CheckStatus") as CheckBox;
if (t.Checked)
{
lista.Add(t);
}
}