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

Virtual Scrolling and Persisting Selected Rows

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 28 Jul 2010, 11:35 PM
I have a grid setup to use Virtual Scrolling as well as having a GridClientSelectColumn.  What I would like to do is be able to select X records from Page 1.  Then scroll to page 3 and select Y more records.  On a postback I want RadGrid1.SelectedItems.Count to be X + Y. Right now it is only showing Y records.  Is this possible?

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 03 Aug 2010, 08:36 AM
Hi Dave,

To achieve the desired functionality you could try keeping all selected rows id's into the server side Dictionary collection:
public Dictionary<string, bool> SelectedItems
{
   get
   {
       if (Session["SelectedItems"] == null)
       {
            Session["SelectedItems"] = new Dictionary<string, bool>();
       }
 
       return Session["SelectedItems"] as Dictionary<string, bool>;
   }
   set
   {
       Session["SelectedItems"] = value;
   }
}

On RadGrid.SelectedIndexChanged event handler you could add the new selected items' ID or remove unselected rows:
void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    SaveSelectedItems();
}
private void SaveSelectedItems()
{
   foreach (GridItem item in RadGrid1.Items)
   {
       if (item is GridDataItem)
       {
           GridDataItem dataItem = item as GridDataItem;
           if (item.Selected)
           {
               if (!SelectedItems.ContainsKey(dataItem["CustomerID"].Text))
               {
                   SelectedItems.Add(dataItem["CustomerID"].Text, true);
 
               }
            }
           else
           {
               if (SelectedItems.ContainsKey(dataItem["CustomerID"].Text))
               {
                  SelectedItems.Remove(dataItem["CustomerID"].Text);
               }
          }
       }
   }
 }

Additionally I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you.

Greetings,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or