asp.net.ph

DetailsView.DataKey Property

System.Web.UI.WebControls Namespace   DetailsView Class


.NET Framework version 2.0

Returns a DataKey object that represents the primary key of the displayed record in a DetailsView control.

Syntax


Script [ DataKey variable ] = DetailsView.DataKey

Property Value


variable A DataKey object that represents the primary key of the displayed record in a DetailsView control.

The property is read only with no default value.

Remarks

When the DataKeyNames property is set, the DetailsView control automatically creates a DataKey object that contains the key/value pairs of the field or fields listed in the DataKeyNames property for the current record.

Use the DataKey property to get this DataKey object. This property is commonly used to obtain the keys and their corresponding values for the fields specified in the DataKeyNames property.

NOTE: As a shortcut, you can also use the SelectedValue property to determine the value of the first key field listed in the DataKeyNames property.

Example

The following example demonstrates how to use the DataKey property to determine the value of the key field bound to the DetailsView control.

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

<script runat = "server">

   void EmployeeDetailsView_ItemCreated ( Object src, EventArgs e ) {
      DataKey key = EmployeeDetailsView.DataKey;
      MessageLabel.Text = "The key value is " + key.Value.ToString ( ) + ".";
   }

</script>
  C# VB

See Also

DetailsView Members   DataKeyNames Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph