Click here to Skip to main content
Licence CPOL
First Posted 22 Jul 2008
Views 11,947
Bookmarked 7 times

How to retrieve multiple datakeys from a FormView control

By | 22 Jul 2008 | Article
This article will show how to retrieve multiple datakeys from a FormView control.

Introduction

This article will show how to retrieve multiple datakey names from a FormView control. I could not find any sample code on the Internet which would show the simplest way to accomplish this task. The following simple code will retrieve multiple datakeys from a FormView.

Background

Basically, you setup a FormView control with multiple datakeys. Now the question is, how do you retrieve multiple keys in your code-behind for accomplishing tasks such as updating?

And on to the sample code...

First, you would define your FormView control with the DataKeyNames containing the multiple keys:

<asp:FormView ID="frvTesting" runat="server" DataKeyNames="UserGroup,UserSubGroup" ...

Now, to access the keys, use the following code. The example below is for the update routine:

Protected Sub frvTesting_ItemUpdating(ByVal sender As Object, _
          ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) _
          Handles frvTesting.ItemUpdating
    Try

        Dim UserGroup_Key, UserSubGroup_Key As String
        ' Get Keys from datakey collection
        UserGroup_Key= frvTesting.DataKey("UserGroup")
        UserSubGroup_Key= frvTesting.DataKey("UserSubGroup")
        ...

Points of interest

Note that the way to retrieve the keys is different from retrieving the keys for a GridView control.

Conclusion

The above was a very simple example on how to retrieve multiple keys from a FormView control.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

SeaWater

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120528.1 | Last Updated 22 Jul 2008
Article Copyright 2008 by SeaWater
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid