Persisting the selected rows client-side on sorting/paging/filtering/grouping

2 posts, 0 answers
  1. HSLaw
    HSLaw avatar
    153 posts
    Member since:
    Jan 2006

    Posted 12 Jan 2010 Link to this post


    Im trying out the sample at
    Here is my page:

    However, the page doesn't maintain the selected row after page change or after sorting.
    Is there something wrong with my code?

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test_grid.aspx.vb" Inherits="test_grid" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
    <html xmlns=""
    <head runat="server"
        <script type="text/javascript"
            var selected = {}; 
            function RadGrid1_RowSelected(sender, args) { 
                var gID = args.getDataKeyValue("gID"); 
                if (!selected[gID]) { 
                    selected[gID] = true; 
            function RadGrid1_RowDeselected(sender, args) { 
                var gID = args.getDataKeyValue("gID"); 
                if (selected[gID]) { 
                    selected[gID] = null; 
            function RadGrid1_RowCreated(sender, args) { 
                var gID = args.getDataKeyValue("gID"); 
                if (selected[gID]) { 
            function GridCreated(sender, eventArgs) { 
                var masterTable = sender.get_masterTableView(); 
                //check whether all items on the active page are selected 
                if (masterTable.get_selectedItems().length == masterTable.get_pageSize()) { 
                    //find the checkbox in the header of the GridClientSelectColumn and set checked state for it - will work with AllowMultiRowSelection = true only! 
                    var gridHeader = masterTable.get_element().getElementsByTagName("TH")[0]; 
                    for (var i = 0; i < gridHeader.childNodes.length; i++) { 
                        if (gridHeader.childNodes[i].id.indexOf("columnSelectCheckBox") > -1) { 
                            gridHeader.childNodes[i].checked = "true"
        <form id="form1" runat="server"
        <telerik:radscriptmanager id="RSM" runat="server" /> 
            <telerik:radgrid runat="server" id="gPoint" allowmultirowselection="True" showfooter="true" 
                runat="server" allowpaging="True" allowsorting="True" skin="Default" horizontalalign="NotSet" 
                width="100%" cellpadding="5"
                                    <pagerstyle position="Top" mode="NextPrevAndNumeric" /> 
       <Selecting AllowRowSelect="True" /> 
          <ClientEvents OnRowCreated="RadGrid1_RowCreated" OnRowSelected="RadGrid1_RowSelected" 
                       OnRowDeselected="RadGrid1_RowDeselected" OnGridCreated="GridCreated" /> 
                                    <mastertableview autogeneratecolumns="False" gridlines="None" ClientDataKeyNames="gID"><NoRecordsTemplate> 
    <div style="text-align:left; vertical-align:middle;">No points found</div> 
        <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" /> 
    <telerik:GridTemplateColumn UniqueName="gID" SortExpression="gID" HeaderText="Serial"
    <%#DataBinder.Eval(Container, "DataItem.gID")%> 

    Imports System.Data 
    Partial Class test_grid 
        Inherits System.Web.UI.Page 
        Protected Sub gPoint_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gPoint.NeedDataSource 
            Dim dt As DataTable = New DataTable 
            Dim dc As DataColumn = New DataColumn 
            dc.ColumnName = "gID" 
            Dim dr As DataRow 
            Dim i As Integer 
            While i <> 50 
                dr = dt.NewRow 
                dr("gID") = System.Guid.NewGuid.ToString 
                i = i + 1 
            End While 
            gPoint.DataSource = dt 
        End Sub 
    End Class 

  2. Yavor
    Yavor avatar
    11 posts

    Posted 15 Jan 2010 Link to this post

    Hello Paladin,

    The Guids do not match.
    On each page load, and every operation - sorting, paging, the stored (previously selected id/guid)
    selected[gID]) is different from the one created for the field. Hence the issue. You will need to make sure that the data remains consistent across postbacks, so that the code can be properly evaluated.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft R3 2016 release webinar banner
Back to Top