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

Persistence of checked items on page navigation.

5 Answers 69 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Lokesh
Top achievements
Rank 1
Lokesh asked on 25 Jun 2013, 06:25 AM
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..

5 Answers, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 27 Jun 2013, 08:51 AM
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.
0
Lokesh
Top achievements
Rank 1
answered on 27 Jun 2013, 01:06 PM
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..
0
Lokesh
Top achievements
Rank 1
answered on 28 Jun 2013, 01:29 PM
Hi Angel Petrov,
Any solution to my problem?

Thanks,
Lok..
0
Accepted
Angel Petrov
Telerik team
answered on 02 Jul 2013, 08:22 AM
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.
0
Lokesh
Top achievements
Rank 1
answered on 05 Jul 2013, 12:02 PM
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..
Tags
Ajax
Asked by
Lokesh
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Lokesh
Top achievements
Rank 1
Share this question
or