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.
Script |
[ DataKey variable ] = DetailsView.DataKey |
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.
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.
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>
<%@ Page language = "VB" %>
<script runat = "server">
Sub EmployeeDetailsView_ItemCreated ( ByVal src As Object, ByVal e As EventArgs )
Dim key As DataKey = EmployeeDetailsView.DataKey
MessageLabel.Text = "The key value is " & key.Value.ToString ( ) & "."
End Sub
</script> |
|
C# |
VB |
DetailsView Members DataKeyNames