html中datakey属性,DetailsView.DataKeyNames 属性 (System.Web.UI.WebControls) | Microsoft Docs

获取或设置一个数组,该数组包含数据源的键字段的名称。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 Example

DetailsView 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 Example

DetailsView 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.

适用于

另请参阅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值