获取或设置一个数组,该数组包含数据源的键字段的名称。Gets or sets an array that contains the names of the key fields for the data source.
public:
virtual property cli::array <:string> ^ DataKeyNames { cli::array <:string> ^ get(); void set(cli::array <:string> ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.StringArrayConverter))]
public virtual string[] DataKeyNames { get; set; }
[]
member this.DataKeyNames : string[] with get, set
Public Overridable Property DataKeyNames As String()
属性值
一个数组,包含数据源的键字段的名称。An array that contains the names of the key fields of the data source.
示例
下面的代码示例演示如何使用 DataKeyNames 属性标识绑定到控件的数据源的键字段 DetailsView 。The following code example demonstrates how to use the DataKeyNames property to identify the key field for the data source bound to the DetailsView control.
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
DetailsView AutoGenerateDeleteButton ExampleDetailsView AutoGenerateDeleteButton Example
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneratedeletebutton="true"
autogeneraterows="true"
allowpaging="true"
runat="server">
forecolor="White"/>
ConnectionString=
""
InsertCommand="INSERT INTO [Customers]([CustomerID],
[CompanyName], [Address], [City], [PostalCode], [Country])
VALUES (@CustomerID, @CompanyName, @Address, @City,
@PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
DetailsView AutoGenerateDeleteButton ExampleDetailsView AutoGenerateDeleteButton Example
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneratedeletebutton="true"
autogeneraterows="true"
allowpaging="true"
runat="server">
forecolor="White"/>
ConnectionString=
""
InsertCommand="INSERT INTO [Customers]([CustomerID],
[CompanyName], [Address], [City], [PostalCode], [Country])
VALUES (@CustomerID, @CompanyName, @Address, @City,
@PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
注解
使用 DataKeyNames 属性指定以逗号分隔的字段名称列表,这些字段名称表示数据源的主键。Use the DataKeyNames property to specify a comma-separated list of field names that represent the primary key of the data source. DataKeyNames设置属性后, DetailsView 控件将自动创建一个 DataKey 对象,该对象表示当前记录的一个或多个键字段,并将其存储在 DataKey 属性中。When the DataKeyNames property is set, the DetailsView control automatically creates a DataKey object that represents the key field or fields for the current record and stores it in the DataKey property. When the AutoGenerateColumns property is also set to true, the DetailsView control automatically ensures that the field or fields specified in the DataKeyNames property are read-only.
备注
必须将属性设置 DataKeyNames 为自动更新、删除和插入控件的功能 DetailsView 才能工作。You must set the DataKeyNames property for the automatic updating, deleting, and inserting features of the DetailsView control to work.
如果 Visible 行字段的属性设置为 false ,则不会在控件中显示行, DetailsView 并且该行的数据不会对客户端进行往返。If the Visible property of a row field is set to false, the row is not displayed in the DetailsView control and the data for the row does not make a round trip to the client. 如果希望不可见的行的数据进行往返,请将字段名称添加到 DataKeyNames 属性。If you want the data for a row that is not visible to make a round trip, add the field name to the DataKeyNames property.
适用于
另请参阅