views:

1066

answers:

2

I have a GridView control on my ASP.NET page that binds to result set when the user executes a search. I create an additional TemplateField column with a CheckBox control to allow the user to select a sub set of records from the result set. I have implemented paging in the GridView control and when the user checks the checkbox control and pages through the result set it does not retain any of the checked checkboxes.

<asp:GridView ID="MyGridView" runat="server" AllowPaging="true" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="MyCheckBox" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Whaat is the best way to retain the checked checkboxes while paging through the GridView?

A: 

you'll need to loop over the rows and save the checked state of the check boxes (along with a datakey) during the gridview paging event. Likewise you will need to read from your saved check state list to re-check the boxes during the gridview rowdatabound event.

Jimmie R. Houts
+1  A: 

You have to maintain the state yourself. This Thread shows how this can be done in VB. just use this VB to C# converter to get your desired code

TStamper