In which cases should I use a GridView's property DataKeyNames
?
Why are multiple columns/fields allowed here?
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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With