what is the use of DATA KEY NAMES property in gridview

Posted by Gow.Net under ASP.NET on 7/25/2012 | Points: 10 | Views : 41133 | Status : [Member] | Replies : 13
what is the use of DATA KEY NAMES property in gridview

gowthaman8870226416


Responses

Posted by: Ranjeet_8 on: 7/25/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Whn d datakeyname prop is set, d gridview control automatically create a datakey obj. for each row in d Gridview control. The datakey object contains d values of d fields specified in d datakeyname property.

To retreive d value frm d gridview in RowDataBound event or any other event of d gridview,
use d below syntax

GridView1.DataKeys[e.Row.RowIndex][0].ToString()
GridView1.DataKeys[e.Row.RowIndex][1].ToString()

or Refer this link:
http://www.codeproject.com/Articles/23833/DataKeyNames

.

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

another example
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx

R D Patel

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/25/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
One more link

http://www.codeproject.com/Articles/23587/GridView-selection-by-key

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 7/25/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
please go thorugh with this article you will come to know

http://www.dotnetfunda.com/articles/article153.aspx

Thanks n Regards
Bhupendra Tiwari

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/24/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

which record selected the Gridview corresponding row we are fetch them like this

Client Side Code

<asp:GridView ID="Grd1" runat="server" DataKeyNames="ID">
</asp:GridView>


Server Side Code

int catid = int.Parse(gdview.DataKeys[e.RowIndex].Value.ToString());



Mark as Answer if its helpful to you

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/24/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 9/24/2012 [Member] Starter | Points: 25

Up
0
Down
it is used to specify primary key of the row

Thanks n Regards
Bhupendra Tiwari

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/25/2012 [Member] Bronze | Points: 25

Up
0
Down
1.The DataKeyNames property is used to identify a record uniquely in the GridView control. A column in the data source is assigned to the DataKeyNames property to identify the record.
2.You must set the DataKeyNames property for the automatic updating and deleting features of the GridView control to work. The values of these key fields are passed to the data source control in order to match the row to update or delete.
3.To set this property declaratively, use a comma-separated list of field names.

public virtual string[] DataKeyNames { get; set; }

Please refer this link too
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames%28v=vs.80%29.aspx

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/25/2012 [Member] Bronze | Points: 25

Up
0
Down
Please mark as answer if it helpful to you..

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/28/2012 [Member] Starter | Points: 25

Up
0
Down
Nice explanation

Thanks & Regards
Hari

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jajati on: 6/5/2013 [Member] Starter | Points: 25

Up
0
Down
very nice posted

fine

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jajati on: 6/5/2013 [Member] Starter | Points: 25

Up
0
Down
very nice posted, thank u

fine

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amitendra on: 7/27/2013 [Member] Starter | Points: 25

Up
0
Down

please fallow the link -
http://aspdotnetweb4u.blogspot.in/2013/07/datakeynames-property-in-aspnet.html

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response