Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to specify the DataKey of a GridView

Posted on 2006-06-27
Medium Priority
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"

Question by:g-spot
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
LVL 16

Accepted Solution

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


Author Comment

ID: 16991881
Thanks Netswap!

Author Comment

ID: 16993011
I'm getting the following error:

"Index was outside the bounds of the array."
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

Author Comment

ID: 16999325
That's fixed it. Thanks netswap :-)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…
Suggested Courses

715 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