Solved

How to specify the DataKey of a GridView

Posted on 2006-06-27
5
448 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 125 total points
Comment Utility
Hi g-spot,
GridView1.DataKeyNames(0) = "departmentID"

Regards,
NetSwap
0
 

Author Comment

by:g-spot
Comment Utility
Thanks Netswap!
0
 

Author Comment

by:g-spot
Comment Utility
I'm getting the following error:

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

Expert Comment

by:Swapnil Piparia
Comment Utility
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
Comment Utility
That's fixed it. Thanks netswap :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now