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

Server side selecting row on other Grid Page

5 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny Scheelings
Top achievements
Rank 1
Danny Scheelings asked on 22 Oct 2009, 11:18 AM
Hi,

I have a RadGrid with Paging, Sorting and Filtering enabled. The datasource is provided in the code-behind using the NeedDataSource event.
Now I want to select a row with a certain DataKeyValue. This is currently done with the folowing method I created:
public void SelectRow<DataKeyType>(DataKeyType dataKeyValue)  
{  
    int index = 0;  
    foreach (Telerik.Web.UI.DataKey key in this.MasterTableView.DataKeyValues)  
    {  
        DataKeyType value = key.Values.OfType<DataKeyType>().FirstOrDefault();  
        this.MasterTableView.Items[index].Selected = (value.Equals(dataKeyValue));  
        index++;  
    }  
The above code works only when the certain DataKeyValue is present on the current Grid Page. Only the DataKeyValues of the current page are present in the DataKeyValues collection.

For as far I know I cannot request the binded datasource (whith filtering and sorting implemented) from the Grid, so I cannot calculate on which Grid Page the DataKeyValue should exist.

Does anybody know how I can select a row on another Page of the Grid? Is there a way to request the binded datasource from the Grid, so I can calculate the PageIndex of the row which must be selected?

Thanx,
Danny

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 22 Oct 2009, 12:09 PM
Hello Danny,

I suggest you review the following forum post which discuss a similar subject and let me know if you need additional assistance:
http://www.telerik.com/community/forums/aspnet-ajax/grid/getting-total-number-of-rows-in-a-grid.aspx

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Danny Scheelings
Top achievements
Rank 1
answered on 22 Oct 2009, 12:17 PM
Hi Pavlina,

Thanks for your quick reply. I already had a similar solution in mind, but I first wanted to know if I did not miss any knowledge of the RadGrid functionality.

So, there is not a way to request the actual datasource (with filtering and sorting taken into account) the Grid is using to Render?

Thanks,
Danny
0
Pavlina
Telerik team
answered on 27 Oct 2009, 01:55 PM
Hello Danny ,

The ItemCommand and SelectedIndexChanged event handlers use the DataKeyValues array to access the primary key of a row when it enters edit mode or when it is selected.
More info is available here:
Retrieving primary key field values for selected items

All the best,

Pavlina
the Telerik team

 


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jorge
Top achievements
Rank 1
answered on 28 Aug 2014, 07:20 PM
I know this is old post and don't really want to fire a new thread but I followed this example to retrieve my primary key value and is not even finding the definitions specified in this link and this post http://www.telerik.com/help/aspnet-ajax/grid-retrieve-primary-key-field-values-for-items.html
0
Princy
Top achievements
Rank 1
answered on 29 Aug 2014, 04:00 AM
Hi Jorge,

I guess you want the datakey value of the selected row in the OnSelectedIndexChanged event. Make sure you have set the DataKeyNames property, and EnablePostBackOnRowClick= true. Take a look at the below code snippet:

ASPX:
<ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
</ClientSettings>
<MasterTableView DataKeyNames="ID">

C#:
protected void rgrdSample_SelectedIndexChanged(object sender, EventArgs e)
{
 string id = (rgrdSample.SelectedItems[0] as GridDataItem).GetDataKeyValue("ID").ToString();
}

Thanks,
Princy
Tags
Grid
Asked by
Danny Scheelings
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Danny Scheelings
Top achievements
Rank 1
Jorge
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or