473,779 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataKeys GridView

34 New Member
Hello,
I have two datakeys defined in the grid view. I want to access the both the datakeys when u click a button. Iam able to access one of the datakeys but not the other. Below is the code

<asp:GridView ID="GridView2" runat="server" AutoGenerateCol umns="False" DataSourceID="S qlDataSource1"
DataKeyNames="S igned_ID,Sessio nCode" CellPadding="4" ForeColor="#333 333" GridLines="None " Width="297px">
<Columns>

The code behind

Protected Sub GetAuthorIDs(By Val sender As Object, ByVal e As System.Web.UI.I mageClickEventA rgs)


For Each row As GridViewRow In GridView2.Rows
' Access the CheckBox
Dim cb As CheckBox = row.FindControl ("chk1")
If cb IsNot Nothing AndAlso cb.Checked Then
' First, get the SignedID for the selected row Iam able to get the first datakey
Dim SignedId = GridView2.DataK eys(row.RowInde x).Value
'CheckedItems.A dd(SignedId.ToS tring())

Response.Write( "SignedID" & SignedId & "<br>")
' Dim strSQL = "Delete from XXXX where Signed_Id=" & SignedId
'SqlDataSource1 .DeleteCommand = strSQL
'SqlDataSource1 .Delete()
//// I want to get the second Datakeyname
Dim sessionID = GridView2.DataK eys(0).Value
Response.Write( sessionID)

End If
Next

End Sub
May 11 '07 #1
1 7365
kenobewan
4,871 Recognized Expert Specialist
An important property that plays a special role in Update and Delete operations is the DataKeyNames property. This property is typically set to the names of fields from the data source that are part of a primary key used to match a given row in the data source. Multiple keys are comma-separated when specifying this property declaratively, although it is common to only have one primary key field. The values of fields specified by the DataKeyNames property are round-tripped in viewstate for the sake of retaining original values to pass to an Update or Delete operation, even if that field is not rendered as one of the columns in the GridView control. When the GridView invokes the data source Update or Delete operation, it passes the values of these fields to the data source in a special Keys dictionary, separate from the Values dictionary that contains new values entered by the user while the row is in edit mode (for update operations). The contents of the Values dictionary are obtained from the input controls rendered for the row in edit mode. To exclude a value from this dictionary, set the ReadOnly property to true on the corresponding.
May 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1084
by: Lingo | last post by:
I'm using beta2. I'm trying to create a gridview dynamically with a passed in SQL statement, everything works paging, sorting, and adding columns dynamically with the code. Because the hidden column isn't accessible anymore I needed to use datakeys to store my key to the record(s) to take actions on. If I use the standard gridview without dynamically creating anything the datakeys are loaded succesfully. If I change any properties...
2
2671
by: Narshe | last post by:
I have a gridview with datakeyname="Id" that is using a sqldatasource. When I click delete on the gridview, the datakeys property is empty during the deleting event.
0
8062
by: ssims | last post by:
I've got a GridView that's sorted by a stored procedure with ROW_NUMBER: PROCEDURE dbo.GetCalendarsByStatusIDPaged ( @startRowIndex int, @maximumRows int, @statusID int ) AS
6
17913
by: Greg | last post by:
Hello, I have a GridView bound to a custom object. I set the DataKeyNames property along with the column DataField properties at design time, and bind the GridView to my object at run-time. In the RowDeleting event, I try to access the DataKeys property, but it contains no elements. This is the first time I'm trying to use DatKeyNames and DataKeys. What am I missing here?
4
4190
by: chris | last post by:
I have a perent gridview which includes in a template field a child gridview. Child gridview includes command buttons for opening different windows based on its row selected. I used the code below. The event for RowDataBound is executed, rows get different color, but event for RowCommand is not executed. What could be the problem ? Thanks a lot in advance.
4
3487
by: =?Utf-8?B?Y2hyaXM=?= | last post by:
I have a perent gridview which includes in a template field a child gridview. Child gridview includes command buttons for opening different windows based on its row selected. I used the code below. The event for RowDataBound is executed, rows get different color, but event for RowCommand is not executed. What could be the problem ? Thanks a lot in advance.
0
1302
by: aj123 | last post by:
I have Table News NewsID, int NewsHeadLint, varcahr(200) OrderNews, int I gridView Display as following query Select ID,NewsHeadLine from News order By OrderNews DESC ---- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="NewsID" EmptyDataText="There are no data records to display." DataSourceID="SqlDataSource1" Style="position: relative; left: 4px; top: 44px;"...
9
4793
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters against one of those invisible columns. How do I accomplish this? The code below that I attempted just returns an empty string when I try to retrieve the invisible column data: gvParts.Rows(e.RowIndex).Cells(8).Text
1
40178
by: jc | last post by:
Duh.. How do I do this? CreditId is my datakey, but I can't seem to get to it. Dim dgItem As GridViewRow For Each dgItem In gridEmployeeCredits.Rows If dgItem.DataItem("CreditId") = 0 Then Dim textboxCreditDate As TextBox = CType(dgItem.FindControl("textboxCreditDate"), TextBox)
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.