Check-box template column loses status after paging

5 posts, 1 answers
  1. Ed
    Ed avatar
    124 posts
    Member since:
    Jan 2008

    Posted 07 Oct 2010 Link to this post

    This must be very simple, so I assume I am at fault for not knowing how to do it!

    I have a RadGrid with a check-box (not populated from the data-source) as follows:

    <telerik:RadGrid ID="rgYoungWeber" runat="server" AllowSorting="true" AllowPaging="true" PagerStyle-Position="Top" DataSourceID="sdsYoungWeber" AutoGenerateColumns="false">
          <telerik:GridBoundColumn DataField="Year" HeaderText="Year"></telerik:GridBoundColumn>
          <telerik:GridBoundColumn DataField="Author" HeaderText="Author"></telerik:GridBoundColumn>      <telerik:GridBoundColumn DataField="Page" HeaderText="Page"></telerik:GridBoundColumn>
            <ItemTemplate><asp:CheckBox id="cb" runat="server" /></ItemTemplate>

    I want to be able to select certain items for printing by ticking the relevant boxes.  I can tick the boxes perfectly well but if I change page and then come back again, the ticks are removed.  How can I enable them to retain their state?  I am using a RadAjaxManagerProxy on the page (with a RadAjaxManager in the corresponding master-page) for partial post-backs: I have tried removing this but the check-boxes still lose their state after paging.

    I am using Telerik DLL 2010.2.713.40 under Windows Server 2008.

    All answers gratefully received,

    Ed Graham
  2. Answer
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2010 Link to this post

    Hello Ed,

    You can do the following to achieve this.
    1. Add an 'OnCheckedChanged' event handler to the CheckBox .
      1. When the CheckBox in checked, store the key values for the selected row in a Session variable.
      2. When the CheckBox is unchecked, remove the key values from the Session variable.
      3. Add a PreRender event handler to the grid.
        1. In the pre-render event of the grid, traverse the rows of the grid and compare their key values to the values saved in the Session variable. Whenever you find a match, check the corresponding Checkbox.

        You can refer the following documentation which explains how to persist the selected rows server-side on sorting/paging/filtering/grouping. Use the same logic and make necessary modification.
        Persisting the selected rows server-side on sorting/paging/filtering/grouping

      4. Ed
        Ed avatar
        124 posts
        Member since:
        Jan 2008

        Posted 08 Oct 2010 Link to this post

        Thanks a lot, Princy -- that worked nicely.  I have to say I'm surprised it's so complicated, though; surely this is what most people would assume should be the default behaviour, isn't it?  I must be missing something ...
      5. JJ
        JJ avatar
        147 posts
        Member since:
        May 2010

        Posted 10 Feb 2011 Link to this post

        Got it. Thanks! 





      6. Allen
        Allen avatar
        50 posts
        Member since:
        Mar 2011

        Posted 27 Jul 2011 Link to this post

        Is there a working example of this for WPF?
      Back to Top