Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to specify the DataKey of a GridView

Posted on 2006-06-27
5
Medium Priority
?
499 Views
Last Modified: 2008-01-09
How do I programatically specify the DataKey of a GridView?

With a DataGrid I could use the following:

datagrid1.DataKeyField = "departmentID"

0
Comment
Question by:g-spot
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 500 total points
ID: 16991347
Hi g-spot,
GridView1.DataKeyNames(0) = "departmentID"

Regards,
NetSwap
0
 

Author Comment

by:g-spot
ID: 16991881
Thanks Netswap!
0
 

Author Comment

by:g-spot
ID: 16993011
I'm getting the following error:

"Index was outside the bounds of the array."
0
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 16998469
Hi g-spot,
you can do it in other tricky way as following as DataKeyNames only except array of strings.

Dim strKeys As String() = {"departmentID"}
GridView1.DataKeyNames = strKeys
0
 

Author Comment

by:g-spot
ID: 16999325
That's fixed it. Thanks netswap :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question