Selected Checkbox list only contains those on the screen

Asked

Viewed 203 times

1

I have a GridView containing a list of items with a checkbox and make use of the code below to "paginate" the table:

$(".gvdatatable").dataTable();

The problem occurs when I check which ones checkboxesare selected, as at this time is only listed to those being displayed on the screen, ie if I select two items from page 1 and select an item on page 2, the code only considers the checkbox selected from page 2. The interesting thing is that if I go back to page 1 the checkbox remains selected. Code of the 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>

Comfort that recovers the checkbox:

foreach (GridViewRow viewRow in dataTables.Rows)
{
     var t = viewRow.Cells[0].FindControl("CheckStatus") as CheckBox;

     if (t.Checked)
     {
        lista.Add(t);
     }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.