Solved

How to specify the DataKey of a GridView

Posted on 2006-06-27
5
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 125 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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