Values Property
Collapse the table of content
Expand the table of content

DataKey.Values Property

Gets an IOrderedDictionary object that contains every key field in the DataKey object.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual IOrderedDictionary Values { get; }

Property Value

Type: System.Collections.Specialized.IOrderedDictionary
An IOrderedDictionary that contains every key field in the DataKey.

Use the Values property to retrieve an IOrderedDictionary object that contains every key field in the DataKey object. The IOrderedDictionary object is often used to iterate through the key fields of a record.

The following code example demonstrates how to iterate through the IOrderedDictionary object returned by the Values property.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void CustomerDetailsView_DataBound(Object sender, EventArgs e)

    // Retrieve the IOrderedDictionary object that contains the key field values.
    IOrderedDictionary allKeysDictionary = CustomerDetailsView.DataKey.Values;

    // Display the the value of the key fields.
    MessageLabel.Text = "The key field values for the displayed record are: <br/><br/>";

    foreach (DictionaryEntry entry in allKeysDictionary)
      MessageLabel.Text += "Key=" + entry.Key.ToString() + 
        ", Value=" + entry.Value.ToString() + "<br/>";



<html xmlns="" >

  <head runat="server">
    <title>DataKey Example</title>
    <form id="form1" runat="server">

      <h3>DataKey Example</h3>

        <asp:detailsview id="CustomerDetailsView"
          datakeynames="CustomerID, CompanyName, PostalCode"  



        <asp:label id="MessageLabel"

        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the Web.config file.                            -->
        <asp:sqldatasource id="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
© 2015 Microsoft