Click here to Skip to main content
6,935,947 members and growing! (16,558 online)
Email Password   helpLost your password?
 
Web Development » ASP.NET Controls » General     Intermediate License: The Code Project Open License (CPOL)

How to retrieve multiple datakeys from a FormView control

By SeaWater

This article will show how to retrieve multiple datakeys from a FormView control.
VB, .NET, ASP.NET, Dev
Revision:2 (See All)
Posted:22 Jul 2008
Views:6,306
Bookmarked:4 times
printPrint Friendly   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 1.78 Rating: 2.29 out of 5
2 votes, 33.3%
1
1 vote, 16.7%
2
1 vote, 16.7%
3

4
2 votes, 33.3%
5

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


Member

Occupation: Web Developer
Location: United States United States

Other popular ASP.NET Controls articles:

 
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.

PermaLink | Privacy | Terms of Use
Last Updated: 22 Jul 2008
Editor: Smitha Vijayan
Copyright 2008 by SeaWater
Everything else Copyright © CodeProject, 1999-2010
Web10 | Advertise on the Code Project