asp:boundfield html,BoundField 类 (System.Web.UI.WebControls) | Microsoft Docs

BoundField 类

定义

表示数据绑定控件中以文本形式显示的字段。Represents a field that is displayed as text in a data-bound control.

本文内容

public ref class BoundField : System::Web::UI::WebControls::DataControlField

public class BoundField : System.Web.UI.WebControls.DataControlField

type BoundField = class

inherit DataControlField

Public Class BoundField

Inherits DataControlField

示例

下面的代码示例演示如何使用 BoundField 对象在控件中显示字段的值 GridView 。The following code example demonstrates how to use a BoundField object to display the values of a field in a GridView control.

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

BoundField Example

BoundField Example

datasourceid="CustomersSqlDataSource"

autogeneratecolumns="false"

autogenerateeditbutton="true"

allowpaging="true"

datakeynames="CustomerID"

runat="server">

readonly="true"

headertext="Customer ID"/>

convertemptystringtonull="true"

headertext="Customer Name"/>

convertemptystringtonull="true"

headertext="Address"/>

convertemptystringtonull="true"

headertext="City"/>

convertemptystringtonull="true"

headertext="ZIP Code"/>

convertemptystringtonull="true"

headertext="Country"/>

selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"

updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)"

connectionstring=""

runat="server">

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

BoundField Example

BoundField Example

datasourceid="CustomersSqlDataSource"

autogeneratecolumns="false"

autogenerateeditbutton="true"

allowpaging="true"

datakeynames="CustomerID"

runat="server">

readonly="true"

headertext="Customer ID"/>

convertemptystringtonull="true"

headertext="Customer Name"/>

convertemptystringtonull="true"

headertext="Address"/>

convertemptystringtonull="true"

headertext="City"/>

convertemptystringtonull="true"

headertext="ZIP Code"/>

convertemptystringtonull="true"

headertext="Country"/>

selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"

updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)"

connectionstring=""

runat="server">

注解

The BoundField class is used by data-bound controls (such as GridView and DetailsView) to display the value of a field as text. BoundField对象的显示方式取决于使用它的数据绑定控件。The BoundField object is displayed differently depending on the data-bound control in which it is used. For example, the GridView control displays a BoundField object as a column, while the DetailsView control displays it as a row.

若要指定要在对象中显示的字段 BoundField ,请将 DataField 属性设置为字段的名称。To specify the field to display in a BoundField object, set the DataField property to the field's name. 通过将属性设置为,可以在显示字段的值之前对其进行 HTML 编码 HtmlEncode true 。The field's value can be HTML-encoded before it is displayed by setting the HtmlEncode property to true. 可以通过设置属性,将自定义格式设置字符串应用于字段的值 DataFormatString 。You can apply a custom formatting string to the field's value by setting the DataFormatString property. 当 HtmlEncode 属性为时 true ,将在自定义格式字符串中使用字段的已编码字符串值。When the HtmlEncode property is true, the encoded string value of the field is used in the custom format string. 默认情况下,仅当数据绑定控件处于只读模式时,才将格式设置字符串应用于字段值。By default, the formatting string is applied to field values only when the data-bound control is in read-only mode. 若要将格式设置字符串应用于数据绑定控件处于编辑模式时显示的值,请将 ApplyFormatInEditMode 属性设置为 true 。To apply the formatting string to values displayed while the data-bound control is in edit mode, set the ApplyFormatInEditMode property to true. 如果字段值为 null,则可以通过设置属性来显示自定义标题 NullDisplayText 。If a field's value is null, you can display a custom caption by setting the NullDisplayText property. BoundField对象还可以通过将属性设置为,自动将空字符串 ( "" ) 字段值转换为 null 值 ConvertEmptyStringToNull true 。The BoundField object can also automatically convert empty string ("") field values to null values by setting the ConvertEmptyStringToNull property to true.

可以 BoundField 通过将属性设置为来隐藏数据绑定控件中的对象 Visible false 。You can hide a BoundField object in a data-bound control by setting the Visible property to false. 若要防止在编辑模式下修改字段的值,请将属性设置 ReadOnly 为 true 。To prevent the value of a field from being modified in edit mode, set the ReadOnly property to true. 在支持 (例如控件) 插入记录的数据绑定控件中 DetailsView ,可以 BoundField 通过将 InsertVisible 属性设置为来隐藏对象 false 。In data-bound controls that support inserting records (such as the DetailsView control), you can hide a BoundField object by setting the InsertVisible property to false. 当您希望在插入模式下隐藏自动生成的键字段时,通常会执行此操作。This is commonly done when you want to hide an automatically generated key field in insert mode.

您可以自定义对象的页眉和页脚部分 BoundField 。You can customize the header and footer sections of a BoundField object. 若要在页眉或页脚部分显示标题,请分别设置 HeaderText 或 FooterText 属性。To display a caption in the header or footer sections, set the HeaderText or FooterText properties, respectively. 您可以通过设置属性来显示图像,而不是在页眉节中显示文本 HeaderImageUrl 。Instead of displaying text in the header section, you can display an image by setting the HeaderImageUrl property. BoundField通过将属性设置为,可以在对象中隐藏标头部分 ShowHeader false 。The header section can be hidden in the BoundField object by setting the ShowHeader property to false.

备注

某些数据绑定控件 (例如 GridView 控件) 可以仅显示或隐藏控件的整个标题部分。Some data-bound controls (such as the GridView control) can show or hide only the entire header section of the control. 这些数据绑定控件不支持 ShowHeader 单个绑定字段的属性。These data-bound controls do not support the ShowHeader property for an individual bound field. 若要显示或隐藏数据绑定控件的整个标题节 (如有) ,请使用控件的 ShowHeader 属性。To show or hide the entire header section of a data-bound control (if available), use the control's ShowHeader property.

还可以 BoundField 通过设置字段的不同部分的样式属性,自定义对象的外观 (字体颜色、背景色等) 。You also can customize the appearance of the BoundField object (font color, background color, and so on) by setting the style properties for the different parts of the field. 下表列出了不同的样式属性。The following table lists the different style properties.

Style 属性Style property

说明Description

对象的子 Web 服务器控件的样式设置 BoundField 。The style settings for the child Web server controls of the BoundField object.

对象的脚注部分的样式设置 BoundField 。The style settings for the footer section of the BoundField object.

对象的标头部分的样式设置 BoundField 。The style settings for the header section of the BoundField object.

对象中数据项的样式设置 BoundField 。The style settings for the data items in the BoundField object.

构造函数

Initializes a new instance of the BoundField class.

字段

此 API 支持产品基础结构,不能在代码中直接使用。

表示“this”表达式。Represents the "this" expression.

属性

获取或设置某些控件中呈现为 AbbreviatedText 属性值的文本。Gets or sets text that is rendered as the AbbreviatedText property value in some controls.

(继承自 DataControlField)

获取或设置一个值,该值指示包含 DataFormatString 对象的数据绑定控件处于编辑模式时,BoundField 属性指定的格式化字符串是否应用到字段值。Gets or sets a value indicating whether the formatting string specified by the DataFormatString property is applied to field values when the data-bound control that contains the BoundField object is in edit mode.

获取对数据控件的引用,该控件与 DataControlField 对象关联。Gets a reference to the data control that the DataControlField object is associated with.

(继承自 DataControlField)

获取 DataControlField 对象所包含的任何 Web 服务器控件的样式。Gets the style of any Web server controls contained by the DataControlField object.

(继承自 DataControlField)

获取或设置一个值,该值指示在数据源中更新数据字段时是否将空字符串值 ("") 自动转换为 null 值。Gets or sets a value indicating whether empty string values ("") are automatically converted to null values when the data field is updated in the data source.

获取或设置要绑定到 BoundField 对象的数据字段的名称。Gets or sets the name of the data field to bind to the BoundField object.

获取或设置字符串,该字符串指定字段值的显示格式。Gets or sets the string that specifies the display format for the value of the field.

获取一个值,该值指示数据控件字段当前是否在设计时环境中进行查看。Gets a value indicating whether a data control field is currently viewed in a design-time environment.

(继承自 DataControlField)

获取或设置数据控件字段脚注的样式。Gets or sets the style of the footer of the data control field.

(继承自 DataControlField)

获取或设置数据控件字段的脚注项中显示的文本。Gets or sets the text that is displayed in the footer item of a data control field.

(继承自 DataControlField)

获取或设置数据控件字段的标题项中显示的图像的 URL。Gets or sets the URL of an image that is displayed in the header item of a data control field.

(继承自 DataControlField)

获取或设置数据控件字段标头的样式。Gets or sets the style of the header of the data control field.

(继承自 DataControlField)

获取或设置显示在数据控件标头中的文本。Gets or sets the text that is displayed in the header of a data control.

获取或设置一个值,该值指示在 BoundField 对象中显示字段值之前,是否对这些字段值进行 HTML 编码。Gets or sets a value indicating whether field values are HTML-encoded before they are displayed in a BoundField object.

获取或设置一个值,该值指示通过将 DataFormatString 属性应用于 BoundField 值而创建的文本在显示时是否应经过 HTML 编码。Gets or sets a value that indicates whether text that is created by applying the DataFormatString property to the BoundField value should be HTML encoded when it is displayed.

获取一个值,该值指示 DataControlField 对象在其父级数据绑定控件处于插入模式时是否可见。Gets a value indicating whether the DataControlField object is visible when its parent data-bound control is in insert mode.

(继承自 DataControlField)

获取一个值,该值指示 DataControlField 对象是否保存对其视图状态的更改。Gets a value indicating whether the DataControlField object is saving changes to its view state.

(继承自 DataControlField)

获取由数据控件字段显示的任何基于文本的内容的样式。Gets the style of any text-based content displayed by a data control field.

(继承自 DataControlField)

获取或设置当字段值为 null 时为字段显示的标题。Gets or sets the caption displayed for a field when the field's value is null.

获取或设置一个值,该值指示是否可以在编辑模式中修改字段的值。Gets or sets a value indicating whether the value of the field can be modified in edit mode.

获取或设置一个值,该值指示是否呈现数据控件字段的标题项。Gets or sets a value indicating whether the header item of a data control field is rendered.

(继承自 DataControlField)

获取或设置数据源控件用来对数据进行排序的排序表达式。Gets or sets a sort expression that is used by a data source control to sort data.

(继承自 DataControlField)

获取一个值,该值指示 BoundField 对象是否支持 HTML 编码。Gets a value indicating whether HTML encoding is supported by a BoundField object.

获取或设置确定控件是否验证客户端输入的值。Gets or sets a value that determines whether the control validates client input or not.

获取或设置一个值,该值指定该控件是否验证客户端输入。Gets or sets a value that specifies whether the control validates client input.

(继承自 DataControlField)

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 DataControlField 对象的视图状态。Gets a dictionary of state information that allows you to save and restore the view state of a DataControlField object across multiple requests for the same page.

(继承自 DataControlField)

获取或设置指示是否呈现数据控件字段的值。Gets or sets a value indicating whether a data control field is rendered.

(继承自 DataControlField)

方法

Creates a duplicate copy of the current DataControlField-derived object.

(继承自 DataControlField)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

设定 BoundField 对象内的单元格中的指定字段值。Formats the specified field value for a cell in the BoundField object.

在设计器中呈现 BoundField 对象时,检索用作字段值的值。Retrieves the value used for a field's value when rendering the BoundField object in a designer.

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)

获取当前实例的 Type。Gets the Type of the current instance.

(继承自 Object)

检索绑定到 BoundField 对象的字段值。Retrieves the value of the field bound to the BoundField object.

还原以前为此字段存储的视图状态信息。Restores the previously stored view-state information for this field.

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

引发 FieldChanged 事件。Raises the FieldChanged event.

(继承自 DataControlField)

保存在页回发到服务器后对 DataControlField 视图状态所做的更改。Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(继承自 DataControlField)

Returns a string that represents this DataControlField object.

(继承自 DataControlField)

使 DataControlField 对象跟踪对其视图状态所做的更改,以便这些更改可以存储在控件的 ViewState 属性中并且能够在同一页的不同请求间得以保持。Causes the DataControlField object to track changes to its view state so they can be stored in the control's ViewState property and persisted across requests for the same page.

(继承自 DataControlField)

确定包含在 BoundField 对象中的控件是否支持回调。Determines whether the controls contained in a BoundField object support callbacks.

显式接口实现

获取一个值,该值指示 DataControlField 对象是否保存对其视图状态的更改。Gets a value indicating whether the DataControlField object is saving changes to its view state.

(继承自 DataControlField)

将数据控件字段还原为保存过的前一视图状态。Restores the data control field's previously saved view state.

(继承自 DataControlField)

保存在页回发到服务器后对 DataControlField 视图状态所做的更改。Saves the changes made to the DataControlField view state since the time the page was posted back to the server.

(继承自 DataControlField)

使 DataControlField 对象跟踪对其视图状态所做的更改,以便这些更改可以存储在控件的 ViewState 属性中并且能够在同一页的不同请求间得以保持。Causes the DataControlField object to track changes to its view state so they can be stored in the control's ViewState property and persisted across requests for the same page.

(继承自 DataControlField)

适用于

另请参阅

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值