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

Get DataKeyValue for Row

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 20 Nov 2008, 11:31 PM
I need to iterate through the items (rows) in a grid and for each row I need to extract the datakeyvalue. Here is how I thought it would be done (This is in the GridDataBound event):

For Each gvRow As Telerik.Web.UI.GridItem In rgViewableDependents.MasterTableView.Items   
 
    strPersonNumber = rgViewableDependents.MasterTableView.DataKeyValues(gvRow.ItemIndex)("PersonNumber")  
    chkViewable = gvRow.FindControl("chkViewable")  
 
Next 

But the strPersonNumber always = Nothing and never get's the key for the row.

rgViewableDependents.MasterTableView.DataKeyValues.Count = 3 and there are 3 rows in the grid, so i'm not sure why it isn't picking up the DataKeyValue. What am I doing wrong?

Thanks!

2 Answers, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 20 Nov 2008, 11:50 PM
It's because I declared the DataKeyNames on the RadGrid rather than on the MasterTableView. I now have it declared in both places and is working fine.
0
Shinu
Top achievements
Rank 2
answered on 21 Nov 2008, 05:03 AM
Hi Joe,

You can also try the following approach to access the datakeyname of a row on the server side.

VB:
 
     Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
         For Each item As GridDataItem In RadGrid1.MasterTableView.Items 
             Dim key As String = item.GetDataKeyValue("keyName").ToString() 
         Next 
     End Sub 
 
 


Thanks
Shinu.
Tags
Grid
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or