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

accessing detail table DataKeys in ItemCreated

2 Answers 394 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt DiPietro
Top achievements
Rank 1
Matt DiPietro asked on 27 Feb 2012, 11:48 PM
I've been trying to find a way to access the DataKey values for a detail table item in the ItemCreated event.  I need to be able to set the NavigateURL control to a javascript function using the DataKey values, but I'm having a hard time finding the correct syntax to access the items.  Is this possible?  Where should I be performing this action so I can set my NavigateURLs correctly?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Feb 2012, 05:42 AM
Hello,

Try the following code to access the DataKeyValue.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if (e.Item.OwnerTableView.Name == "DetailTableName")
 {
  GridTableView dtable = (GridTableView)e.Item.OwnerTableView;
  GridDataItem parentItem = (GridDataItem)dtable.ParentItem;
  string dataKey= parentItem.GetDataKeyValue("DataKeyName").ToString();
 }
}

-Shinu.
0
Matt DiPietro
Top achievements
Rank 1
answered on 28 Feb 2012, 02:50 PM
That didn't work, but it got me part of the way there.  What I needed was:

e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex).Item(0)

Thanks for pointing me in the right direction.
Tags
Grid
Asked by
Matt DiPietro
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Matt DiPietro
Top achievements
Rank 1
Share this question
or