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

RadGrid Get Primary Key When Item Created

2 Answers 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 11 Nov 2011, 03:54 PM
Hi,

I am using this demo to allow me to open rad windows from my RadGrid:  http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid

My challenge is that I need to encrypt my URL parameters server side.  I think this would be simple if I could grab the Primary Key as each item is created on the grid.  But, I cannot seem to get the syntax correct to get that ID of the items DataKey.  I've tried variations of this statement:

Dim myIndex As Integer = e.Item.ItemIndex
 
If myIndex > 0 Then
 
    Dim myPK As String = e.Item.OwnerTableView.Items(myIndex)("QuestionID").Text
 
    'Then encrypt from here and add to the function defined in the link in the "template" column.
 
End If

Most of my errors seem to be around e.Item.ItemIndex.  Any help?

Jim

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 14 Nov 2011, 04:50 AM
Hello James,

In order to access the primary key value, try the following code snippet in ItemDataBound event.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
    GridDataItem item = (GridDataItem)e.Item;
    string val = item.GetDataKeyValue("QuestionID").ToString();
 }
}

-Shinu.
0
James
Top achievements
Rank 1
answered on 15 Nov 2011, 05:17 AM
Thank you very much.  This looks like it is working!

Jim
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
James
Top achievements
Rank 1
Share this question
or