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

Getting DataKeyValue of top grid when expanding to display NestedView Template

1 Answer 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl Wilkens
Top achievements
Rank 1
Karl Wilkens asked on 27 Sep 2012, 02:41 PM
Hi,

I am trying to get the datakey value of a row when expanding it to display a nestedViewTemplate.

When the grid is initially populated, I get the datakey values fine within the ItemCreated event.

Dim myID = CInt(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("whatever"))


But when the expand icon is clicked that code throws an error - {"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"}

Any thoughts on what I am doing wrong here? Thanks.

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Sep 2012, 04:42 PM
Hello,

Please try with below code snippet.

// Access current item
GridNestedViewItem citem = e.Item as GridNestedViewItem;
string cID = citem.GetDataKeyValue("whatever").ToString() ;
 
// Access Parent Item
GridDataItem pitem = ((GridNestedViewItem)e.Item).ParentItem as GridDataItem;
string pID = pitem.GetDataKeyValue("whatever").ToString() ;

also check below link for reference.
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-get-the-parent-griddataitem-from-a-nested-view-control.aspx

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Karl Wilkens
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or