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

Simple server-side row selecting and accessing row data

2 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 2
Darren asked on 09 Jul 2012, 04:18 PM
I've been searching through the documentation to do a simple server-side select and access the data in that row. I found this page here (http://www.telerik.com/help/aspnet-ajax/grid-retrieve-primary-key-field-values-for-items.html) and used a line from the sample code:

RadGrid1.SelectedItems[0].GetDataKeyValue("CustomerID").ToString()

Visual Studio gives me an error of "'Telerik.Web.UI.GridItem' does not contain a definition for 'GetDataKeyValue' and no extension method 'GetDataKeyValue' accepting a first argument of type 'Telerik.Web.UI.GridItem' could be found (are you missing a using directive or an assembly reference?)"

I tried a different route using this:

grd.SelectedItems[0].Cells[1].Text

but this doesn't return anything at runtime, regardless of the index I use for the cells collection.

Please advise. Thanks guys!

2 Answers, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 09 Jul 2012, 06:19 PM
Hi Darren,

Try casting RadGrid1.SelectedItems[0] as a GridDataItem. 

I hope this helps!
Casey

GridDataItem selItem = RadGrid1.SelectedItems[0] as GridDataItem;
selItem.GetDataKeyValue("CustomerID").ToString();

0
Darren
Top achievements
Rank 2
answered on 09 Jul 2012, 06:47 PM
That worked. Thank you!
Tags
Grid
Asked by
Darren
Top achievements
Rank 2
Answers by
Casey
Top achievements
Rank 1
Darren
Top achievements
Rank 2
Share this question
or