473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

GridView.DataKey

21
hello every body my name is furqan ahmed and i am new to asp.net and so to .net controls can any tell me what the following code is saying and what does datakey means thanxxx

i am waiting for ur reply i shall be vey thankfull to ya

Expand|Select|Wrap|Line Numbers
  1. <%@ Page language="C#" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <script runat="server">
  6.  
  7.   void CustomerDetailsView_DataBound(Object sender, EventArgs e)
  8.   {
  9.     // Get the DataKey object for the current record.
  10.     DataKey key = CustomerDetailsView.DataKey;
  11.  
  12.     // Display the the value of the key field.
  13.     MessageLabel.Text = "The key field value for the displayed record is " + 
  14.       key.Value.ToString() + ".";
  15.   }
  16.  
  17. </script>
  18.  
  19. <html  >
  20.  
  21.   <head runat="server">
  22.     <title>DataKey Example</title>
  23. </head>
  24. <body>
  25.     <form id="form1" runat="server">
  26.  
  27.       <h3>DataKey Example</h3>
  28.  
  29.         <asp:detailsview id="CustomerDetailsView"
  30.           datasourceid="DetailsViewSource"
  31.           autogeneraterows="true"
  32.           datakeynames="CustomerID"  
  33.           allowpaging="true"
  34.           ondatabound="CustomerDetailsView_DataBound" 
  35.           runat="server">
  36.  
  37.         </asp:detailsview>
  38.  
  39.         <br/>
  40.  
  41.         <asp:label id="MessageLabel"
  42.           forecolor="Red"
  43.           runat="server"/>
  44.  
  45.         <!-- This example uses Microsoft SQL Server and connects  -->
  46.         <!-- to the Northwind sample database. Use an ASP.NET     -->
  47.         <!-- expression to retrieve the connection string value   -->
  48.         <!-- from the Web.config file.                            -->
  49.         <asp:sqldatasource id="DetailsViewSource"
  50.           selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
  51.           connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
  52.           runat="server"/>
  53.  
  54.       </form>
  55.   </body>
  56. </html>
  57.  
Feb 19 '10 #1
2 2860
CroCrew
564 Expert 512MB
Hello furqi,

We will be happy to help you out. But, can I ask something of you? From today going forward when asking for help and filling out the form could you please not put “hi every body” in the Question field. Next time type something in that field that sums up your question/problem.

Thanks,
CroCrew~
Feb 19 '10 #2
tlhintoq
3,525 Expert 2GB
To add on to what CroCrew said there is a FAQ that helps with writing questions and subjects in the best way possible to get the most targeted help. Please visit the Posting Guidelines for tips on how to ask questions to get the best help.

Moving on to your question "What is a DataKey?" It is the object type. That is standard syntax is C#. First the type, then the name of that instance.

Button myButton = new Button();
DataKey myDataKey = new DataKey();

Same thing. For details on how what a DataKey does and is (or any .NET object) I always recommend going to the MSDN. My favorite search method is to hit google with "MSDN {thing}" In this case going a Google for "MSDN DataKey" gets you what you need.
http://msdn.microsoft.com/en-us/libr...0).aspx?ppud=4
Feb 19 '10 #3

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

Similar topics

1
by: mike | last post by:
i'd like to get datakey of GridView So i write code like below but it wasn't work well. how should i do? protected void BookGridView_RowDataBound(object sender, GridViewRowEventArgs e) { int...
1
by: Mark Richards | last post by:
I posted this earlier, and got no response. Basically I need to be able to grab a value from one of the fields in a gridView to populate a dropdown in another column of the gridview: I have a...
5
by: NH | last post by:
How do I find out the row index selected in the gridveiw row command method? I have an imageButton in a gridview cell and its corresponding code in the row command method needs to know the row...
1
by: Steven Blair | last post by:
Here is my problem: I have a GridView with a Select column. Once the user clicks the Select button the following things need to happen. 1. Need to store the DataKey of the selectedindex 2....
1
by: ram_kri | last post by:
Hi Guys, Here is a uncommon scenario that I had to work on.. I have a GridView which is associated to a DataSource. But I have a couple of columns (item-templates while the rest of the columns...
3
by: denvercr | last post by:
Hi how do i possibly get the value of a hidden column (id) of a gridview binded in sqldatasource? i have this code in C# usng GridViewRow and DataKey Classes to retrieve it, I also set the...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
0
by: VB Programmer | last post by:
From the research I've done, when you are using a gridview and want to programatically refer to a column that is hidden you have to add it to the datakey of the gridview. I've done that for 2 of...
7
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
Is there a way to use a gridview in a timecard application, and if so, how? I was looking at using a gridview to display a person's hours worked in a week. To do this, many different data records...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview control with a template column that has a textbox and when the control is bound to the datasource the textbox is filled ok. I then change what is in the textbox in the gridview...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.