Get selected items through all pages

13 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 11 Jan 2013 Link to this post

    Requirements

    RadControls version Q3 2012
    .NET version 4
    Visual Studio version 2010
    programming language C#, VB
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION

    This project demonstrates how to persist selected rows through rebind operations such as paging, sorting, filtering, grouping, etc. using the approach provided here. In addition to that,it gives a clear example how to pass the selected items' ID collection to the server using a HiddenField. On a server event handler, a button click for instance, one can loop through all of the grid records and execute their custom logic for the selected items, even if the items' count has been modified by filtering, deleting, etc.

    Important: Please note that this approach requires additional grid Rebind() in case paging is enabled. This is the only way to get all of the grid items since only the visible rows are loaded at the current time.


  2. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 05 Jul 2013 Link to this post

    Hi ,
    Yes, we do get the selected DataKeys from all pages. 
    But when iterating through grid items on a button click 

            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
            {
                if (selectedKeys.Contains(dataItem.GetDataKeyValue("OrderID").ToString()))
                {
                    selectedVisible.Add(dataItem.GetDataKeyValue("OrderID").ToString());
                }
            }

    RadGrid1.MasterTableView.Items  gives items on the current page only whereas user has selected rows from different pages.
    So, the control simply will not enter in If condition all the time.
    I mean, selectedKeys hashset has DataKeys from different pages and in foreach statement we are iterating through griditems on current page only.
    It would have been better if somehow we could have got the collection of GridItems on different pages because user is selecting items from different pages.
    So it would have been a lot easier to iterate through only selected GridItems if we could have got the collection of Giditems like we get the collection of datakeys from different pages.

    Thanks,
    Lok..
  3. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 10 Jul 2013 Link to this post

    Hello Lok,

    The following snippet used in the code-behind of the project enables us to iterate through all of the items in the grid, not only on the current page:
    RadGrid1.AllowPaging = false;
    RadGrid1.Rebind();

    Hope the clarification was helpful.

    Regards,
    Eyup
    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.
  4. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2013 Link to this post

    Yes..That was it..
    Its working perfect..
    Thank you so much...
    And sorry for my late response..
    :) :)
  5. Rohit
    Rohit avatar
    1 posts
    Member since:
    Jul 2013

    Posted 17 Jul 2013 Link to this post

    Hi,

    This works perfectly fine for me except for one thing...I want to allow the user to be able to select multiple rows(on clicking anywhere on a row)
    without using ctrl key.

    I tried to do it by looping through all the rows of the Grid in the onRowSelected event and then checking if selected is true for them, but it doesn't work.

    Can you please help me with this.

    Regards,
    Rohit
  6. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 22 Jul 2013 Link to this post

    Hello Rohit,

    Please note that this is the default and expected behavior and you are supposed to hold Ctrl key down when selecting multiple items without the use of the ClientSelectColumn. You can use the following approach to achieve the requested functionality:
    <ClientSettings>
        <Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true" />
        <ClientEvents OnRowClick="toggleSelection" />
    </ClientSettings>
    JavaScript:
    function toggleSelection(sender, args) {
        args.get_gridDataItem().set_selected(!args.get_gridDataItem().get_selected());
    }

    That should do the trick.

    Regards,
    Eyup
    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. Ankush
    Ankush avatar
    4 posts
    Member since:
    Dec 2013

    Posted 10 Dec 2013 Link to this post

    HI Eyup ,

    I am selecting all rows in the radgrid in pre-render event.

     protected void rgDiagnosis_PreRender(object sender, EventArgs e)
            {   
                    foreach (GridDataItem item in rgDiagnosis.MasterTableView.Items)
                    {
                            item.Selected = true;
                    }
            }
    When I click on any row, all other rows get deselected.

    I want all rows to hold their selection and only row selection toggle on row click. Please help.

    Thanks,
    Anksh


  8. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 13 Dec 2013 Link to this post

    Hi Anksh,

    Please try the suggested approach in my previous post which addresses the exact same behavior.

    Regards,
    Eyup
    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.
  9. Ankush
    Ankush avatar
    4 posts
    Member since:
    Dec 2013

    Posted 13 Dec 2013 Link to this post

    Hi Eyup,

    I used the code you had suggested but it didn't work for me.

    Still, when I click on any row, all the other rows get deselected. Please help !

    I am using Telerik ddl File version : 2013.1.417.40

    Thanks,
    Ankush
  10. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 18 Dec 2013 Link to this post

    Hello Ankush,

    I have created a sample RadGrid web site to demonstrate that the suggested approach works as expected. Can you please run the attached application and verify that it works as expected on your side, too?

    Regards,
    Eyup
    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.
  11. Ankush
    Ankush avatar
    4 posts
    Member since:
    Dec 2013

    Posted 11 Jan 2014 Link to this post

    Hi Eyup,

    Many thanks for your reply and sample code but it is still not working for me. It is still deselecting all rows on click of one row.

    Thanks,
    Ankush
  12. Ankush
    Ankush avatar
    4 posts
    Member since:
    Dec 2013

    Posted 12 Jan 2014 Link to this post

    Hi Eyup,

    You are a life saver. The sample code worked for me after  slight modifications in my code. Many thanks for the help. Really appreciate the same.

    Ankush
  13. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 21 Jan 2015 Link to this post

    Attached you can find the improved version of the sample.

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top