![]() |
Web Development »
ASP.NET Controls »
General
Intermediate
License: The Code Project Open License (CPOL)
How to retrieve multiple datakeys from a FormView controlBy SeaWaterThis article will show how to retrieve multiple datakeys from a FormView control. |
VB, .NET, ASP.NET, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
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?
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")
...
Note that the way to retrieve the keys is different from retrieving the keys for a GridView control.
The above was a very simple example on how to retrieve multiple keys from a FormView control.
General
News
Question
Answer
Joke
Rant
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 |