Persistence of checked items on page navigation.

6 posts, 2 answers
  1. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 25 Jun 2013 Link to this post

    Hi Team,
    I have a radgrid with ClientSelectColumn.
    I select a row on first page of the grid, move to second page select 3 rows on second page.
    When I come back to first page, my selection on the first page disappears. I mean the selection does not persist.
    So I tried what has been said in this post. It works very well as far as visualisation is concerned. It does show that I have my rows selected from different pages.
    But when on a button click (outside the grid) I try to loop through this collection, all I get is the records from current selected page and not all the rows selected from different pages.

    foreach (GridDataItem item in RadGrid1.SelectedItems)
    {
    ..// Code here
    }

    RadGrid1.SelectedItems  gives rows from the current selected page only and not the entire selection.

    Will you please help me with this?
    Any help appreciated.

    Thanks,
    Lok..
  2. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 27 Jun 2013 Link to this post

    Hello Lokesh,

    I have to say that the behavior experienced is expected. You can only loop the items which are on the current page. That said you will have to store the selected GridDataItems in a separate collection and persist the selection using server-side logic. This is achievable by subscribing to the OnItemCommand event of the grid and saving/removing the selected/deselected item from the local collection. Additionally you should subscribe to the on OnItemDataBound event in order to persist the selection. A sample demonstration of this can be found in the attached website.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 27 Jun 2013 Link to this post

    Hi Angel Petrov,
    Thanks for your helping hand.The solution works very well.
    But it still have two problems.
    1.  How to get records in session when user clicks Select All Items checkbox (the one in the header)?
    Because no event occurs when user checks the select all checkbox in header. If any event occurs, please explain what that event is.
    2. How to get records in session when user selects multiple rows by dragging the mouse over rows?

    Could you please help me at this?

    Thanks,
    Lok..
  5. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 28 Jun 2013 Link to this post

    Hi Angel Petrov,
    Any solution to my problem?

    Thanks,
    Lok..
  6. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 02 Jul 2013 Link to this post

    Hi Lokesh,

    In order to store the data items which are selected on the client in the ViewState you should fire an AJAX request and pass as a parameter the ids of the items. If we refer to the previously provided example you can try something like this:

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1"  OnAjaxRequest="RadAjaxManager1_AjaxRequest" runat="server">
          ....
        </telerik:RadAjaxManager>
        <asp:Button ID="Button1" Text="CheckSelected" OnClientClick="GetSelectedItems()" runat="server" />
            <script type="text/javascript">
                function GetSelectedItems() {
                    var tableView = $find('<%=RadGrid1.ClientID%>').get_masterTableView();
                var selectedItems = tableView.get_selectedItems();
                var ids = "";
                for (var i = 0; i < selectedItems.length; i++) {
                    ids += selectedItems[i].getDataKeyValue("MailID") + " ";
                }
                $find('<%=RadAjaxManager1.ClientID%>').ajaxRequest(ids);
            }
        </script>

    C#
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
       {
           if (e.Argument.Length > 0)
           {
               string[] keyNames = e.Argument.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
               foreach (var selectedItemDataKeyName in keyNames)
               {
                   if (selectedItemsDataKeyNames.Contains(selectedItemDataKeyName) == false)
                   {
                       selectedItemsDataKeyNames.Add(selectedItemDataKeyName);
                       selectedItems.Add(RadGrid1.MasterTableView.FindItemByKeyValue("MailID", selectedItemDataKeyName));
                   }
               }
           }
       }


    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  7. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 05 Jul 2013 Link to this post

    Hi Angel Petrov,
    Your solution helped me. Not in this Persistence scenario, but in another case where I needed to pass ids from client side to server side using Ajax Request.
    Thank you very much for your helping hand.

    Thanks,
    Lok..
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017