views:

1417

answers:

2

Hi,

I need to get the DataKeyNames in codebehind of my ASP.NET application (VB.NET). How can I get that?

+2  A: 

This way (VB.NET code):

 For Each dkn As String in GridView1.DataKeyNames
     ' -- Do something here with dkn
 Next

DataKeyNames is an array of strings, so there can be more than one in a GridView. You can access the array members this way (example):

Dim FirstKeyName as String = GridView1.DataKeyNames(0)

Here is the documentation on MSDN of the DataKeyNames property.

splattne
Nice quick change to VB.NET!
Andy White
I like VB.NET too and I use it often.
splattne
A: 
Dim s As String = GridView1.DataKeyNames(0)
BenB