Solved

How to specify the DataKey of a GridView

Posted on 2006-06-27
5
470 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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