This is a migrated thread and some comments may be shown as answers.

Check-box template column loses status after paging

4 Answers 269 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 07 Oct 2010, 03:33 PM
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">
  <MasterTableView>
    <Columns>
      <telerik:GridBoundColumn DataField="Year" HeaderText="Year"></telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="Author" HeaderText="Author"></telerik:GridBoundColumn>      <telerik:GridBoundColumn DataField="Page" HeaderText="Page"></telerik:GridBoundColumn>
      <telerik:GridTemplateColumn>
        <ItemTemplate><asp:CheckBox id="cb" runat="server" /></ItemTemplate>
      </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>

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

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Oct 2010, 11:25 AM
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

      Thanks,
      Princy.
      0
      Ed
      Top achievements
      Rank 1
      answered on 08 Oct 2010, 12:45 PM
      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 ...
      0
      JJ
      Top achievements
      Rank 1
      answered on 10 Feb 2011, 03:46 PM

      Got it. Thanks! 

       

       

       

       

      0
      Allen
      Top achievements
      Rank 2
      Iron
      Veteran
      answered on 27 Jul 2011, 11:03 PM
      Is there a working example of this for WPF?
      Tags
      Grid
      Asked by
      Ed
      Top achievements
      Rank 1
      Answers by
      Princy
      Top achievements
      Rank 2
      Ed
      Top achievements
      Rank 1
      JJ
      Top achievements
      Rank 1
      Allen
      Top achievements
      Rank 2
      Iron
      Veteran
      Share this question
      or