Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of DataKeyNames in an ASP.NET GridView?

In which cases should I use a GridView's property DataKeyNames?

Why are multiple columns/fields allowed here?

like image 283
jeevamuthu Avatar asked Jun 02 '11 05:06

jeevamuthu


People also ask

What is the use of DataKeyNames in GridView in ASP NET?

When the DataKeyNames property is set, the GridView control automatically populates its DataKeys collection with the values from the specified field or fields, which provides a convenient way to access the primary keys of each row. The GridView control stores these key field values in the control state.

What is the difference between Datagridview and GridView?

The DataGrid control raises single events for operations, while the GridView control is capable of both pre-operation and post-operation events. The GridView control supports the Sorting event that occurs when a field is sorted.

What is GridView control explain the properties of GridView control?

The GridView control is used to display the values of a data source in a table. Each column represents a field, while each row represents a record. The GridView control supports the following features: Binding to data source controls, such as SqlDataSource.

What is GridView used for?

A GridView is a type of AdapterView that displays items in a two-dimensional scrolling grid. Items are inserted into this grid layout from a database or from an array. The adapter is used for displaying this data, setAdapter() method is used to join the adapter with GridView.


2 Answers

Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.

GridView.DataKeyNames Property

GridView.DataKeys Property

like image 69
Muhammad Akhtar Avatar answered Sep 19 '22 16:09

Muhammad Akhtar


It keeps the primary key fields or id field of data table, which gridview shows.
According to MSDN

Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.

like image 41
jams Avatar answered Sep 17 '22 16:09

jams