asp.net.ph

FormView.DataKey Property

System.Web.UI.WebControls Namespace   FormView Class


.NET Framework version 2.0

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

Syntax


Script [ DataKey variable ] = FormView.DataKey

Property Value


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

The property is read only with no default value.

Remarks

When the DataKeyNames property is set, the FormView 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 FormView control.

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

<script runat = "server">

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

</script>
  C# VB

See Also

FormView 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