Using Data Keys
You associate a value with each row in a GridView
by providing a value for the GridView
control’s DataKeyNames
property. You can assign the name of a single database column to this property, or you can assign a comma-separated list of column names to this property.
For example, the Employees database table uses two columns—the employee first and last name—as a primary key. The page in Listing 11.4 displays employee details when you select a particular employee (see Figure 11.3).
Figure 11.3. Displaying employee details.
Listing 11.4. SelectDataKeys.aspx
In Listing 11.4, the SelectedDataKey()
method retrieves the primary ...
Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.