7 Answers, 1 is accepted
I think that the example from this section of the documentation can become a good starting point for your custom implementation:
http://www.telerik.com/help/aspnet-ajax/grdselectedrowatalltimes.html
Feel free to extend/modify the solution to conform to your additional requirements.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
In my page, RadGrid is on left side panel and edit form is on right side panel. When I select any row in the grid it fires SelectedIndex event but row is still not in edit mode due to which I can not insert the Item data bound code in my code files.
I got few ideas from your post, I am able to get the row index of the row which is getting updated. But now i am unable to select this row from the binded RadGrid datasource.
I have tried both of the following ways
RadGrid1.MasterTableView.Items[(int)Session["selUserIndex"]].Selected = true;
RadGrid1.Items[(
int)Session["selUserIndex"]].Selected = true;
but giving following error
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Reason is paging, in items count gives the number of rows of particular page and the selected index count may exceeds this. I want to set the selected row from whole data source count and not the master table view items count.
Hi Meghna,
Indeed in your scenario with paging enabled the grid's Items collection will contain the rows on the current page only (the same is true for the standard MS GridView control). If you would like to select an item on a different page, you will need to traverse the underlying data source, find the record in question, change the CurrentPageIndex of the grid (to navigate to this page), rebind it and then select the row there.
How to iterate through all items in the grid source you can see from this help topic:
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html (paragraph 'Displaying totals for all grid pages')
Regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Question 2: Also every time when I update the any row, the fresh data will come from database. I am able to retrieve the updated row in fresh datasource but how i am able to get the page on which this updated row will come.
e.g while updating it was on 1st page but after updation it might fall under page 4. Then how can i know the new page number.
- You can change the page index of the grid inside the PreRender server event of the grid and refresh it invoking its Rebind() method.
- The same approach with iterating through the items in the underlying data source should be applicable in this case. Then you can navigate to the page which holds the record using the technique from point 1.
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Users
updatedUser = (Users)ViewState["ManageApplicationUserSelectedUser"];
for (int pageCount = 0; pageCount < RadGrid1.PageCount; pageCount++)
{
for (int rowCount = 0; rowCount < RadGrid1.MasterTableView.Items.Count; rowCount++)
{
if (updatedUser.ObjectGuid.Equals(RadGrid1.MasterTableView.Items[rowCount]["ObjectGuid"].ToString()))
{
RadGrid1.CurrentPageIndex = pageCount;
RadGrid1.MasterTableView.Items[rowCount].Selected =
true;
}
}
}
Above is my code snippet.
There I am traversing with each item of the RadGrid and comapring one of its cell value with my viewstate value. If its matches to true that means this particular row of RadGrid datasource is updated. Now my question is how can i get page for this row.
And onec i get the page i will rebind() the RadGrid. After that how am i get the rowcount of the updated user and how i navigate my paging to that particular page which contains this updated row.
Can you please provide small simple code snippet which i can integrate in my application.
You can try out the following code to search for the updated item and set it selected:
c#:
| Users updatedUser = (Users)ViewState["ManageApplicationUserSelectedUser"]; |
| int flag = 0; |
| for (int i = 0; i < RadGrid1.MasterTableView.PageCount; i++) |
| { |
| RadGrid1.CurrentPageIndex = i; // set the page index to the current page |
| RadGrid1.Rebind(); |
| foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items) |
| { |
| if (updatedUser.ObjectGuid.Equals(dataItem["ObjectGuid"].Text )) //search for the updated text |
| { |
| dataItem.Selected = true; //select the row |
| flag = 1; |
| } |
| } |
| if (flag == 1) |
| break; |
| } |
Thanks
Princy.