CheckBoxField 类

定义

表示数据绑定控件中以复选框形式显示的布尔型字段。Represents a Boolean field that is displayed as a check box in a data-bound control.

public ref class CheckBoxField : System::Web::UI::WebControls::BoundField
public class CheckBoxField : System.Web.UI.WebControls.BoundField
type CheckBoxField = class
    inherit BoundField
Public Class CheckBoxField
Inherits BoundField
继承

示例

下面的代码示例演示如何使用CheckBoxField GridView控件中的对象, 以使用布尔数据类型从 Microsoft SQL Server 数据源显示字段。The following code example demonstrates how to use a CheckBoxField object in a GridView control to display a field from a Microsoft SQL Server data source with a Boolean data type.


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>CheckBoxField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>CheckBoxField Example</h3>

      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="au_lname"
            headertext="Last Name"/>
                    
          <asp:checkboxfield datafield="contract"
            text="Contract"
            headertext="Contract"/>     
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>


<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>CheckBoxField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>CheckBoxField Example</h3>

      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="au_lname"
            headertext="Last Name"/>
                    
          <asp:checkboxfield datafield="contract"
            text="Contract"
            headertext="Contract"/>     
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

注解

数据绑定控件 ( GridView如和DetailsView) 使用类在复选框中显示布尔数据字段的值。CheckBoxFieldThe CheckBoxField class is used by data-bound controls (such as GridView and DetailsView) to display the value of a Boolean data field in a check box. CheckBoxField对象的显示方式取决于使用它的数据绑定控件。The CheckBoxField object is displayed differently depending on the data-bound control in which it is used. 例如, GridView控件以列的形式CheckBoxField显示对象, 而DetailsView控件则将其显示为一行。For example, the GridView control displays a CheckBoxField object as a column, while the DetailsView control displays it as a row.

备注

复选框处于禁用状态 (只读), 直到数据绑定控件在编辑模式下显示包含复选框的记录。A check box is disabled (read-only) until the data-bound control displays a record that contains the check box in edit mode. 若要详细了解如何将记录置于编辑模式, 请参阅包含CheckBoxField对象的父控件的文档。For more information on how to put a record into edit mode, see the documentation for the parent control that contains the CheckBoxField object.

若要指定要在CheckBoxField对象中显示的字段, 请使用字段的名称DataField设置属性。To specify the field to display in a CheckBoxField object, set the DataField property with the field's name.

备注

由于复选框只能显示选定或未选择的状态, CheckBoxField因此对象只能绑定到具有布尔数据类型的字段或可由Parse分析的字符串。Because a check box can display only a selected or an unselected state, a CheckBoxField object can be bound only to a field with a Boolean data type or a string that can be parsed by Parse.

通过设置Text属性, 您可以在每个复选框旁边显示标题。You can display a caption next to each check box by setting the Text property. 当属性设置为false时, 将在数据绑定控件中隐藏对象。CheckBoxField VisibleA CheckBoxField object is hidden in a data-bound control when the Visible property is set to false. 若要防止在编辑模式下修改字段的值, 请将ReadOnly属性设置为。 trueTo prevent the value of a field from being modified in edit mode, set the ReadOnly property to true. 在支持插入记录的数据绑定控件DetailsView (如控件) 中, 可以通过将InsertVisible属性设置为CheckBoxFieldfalse隐藏插入模式下的对象。In data-bound controls that support inserting records (such as the DetailsView control), you can hide a CheckBoxField object in insert mode by setting the InsertVisible property to false.

您可以自定义CheckBoxField对象的页眉和页脚部分。You can customize the header and footer sections of a CheckBoxField object. 若要在页眉或页脚部分显示标题, 请分别设置HeaderTextFooterText属性。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. 通过CheckBoxField false将属性设置为, 可以在对象中隐藏标头部分。 ShowHeaderThe header section can be hidden in the CheckBoxField 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.

还可以通过设置字段的不同部分CheckBoxField的样式属性来自定义对象 (字体颜色、背景色等) 的外观。You also can customize the appearance of the CheckBoxField 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
ControlStyle CheckBoxField对象的子 Web 服务器控件的样式设置。The style settings for the child Web server controls of the CheckBoxField object.
FooterStyle CheckBoxField对象的脚注部分的样式设置。The style settings for the footer section of the CheckBoxField object.
HeaderStyle CheckBoxField对象的标头部分的样式设置。The style settings for the header section of the CheckBoxField object.
ItemStyle CheckBoxField对象中数据项的样式设置。The style settings for the data items in the CheckBoxField object.

构造函数

CheckBoxField()

初始化 CheckBoxField 类的新实例。Initializes a new instance of the CheckBoxField class.

属性

AccessibleHeaderText

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

(继承自 DataControlField)
ApplyFormatInEditMode

重写 ApplyFormatInEditMode 属性。Overrides the ApplyFormatInEditMode property. CheckBoxField 类不支持该属性。This property is not supported by the CheckBoxField class.

Control

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

(继承自 DataControlField)
ControlStyle

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

(继承自 DataControlField)
ConvertEmptyStringToNull

重写 ConvertEmptyStringToNull 属性。Overrides the ConvertEmptyStringToNull property. CheckBoxField 类不支持该属性。This property is not supported by the CheckBoxField class.

DataField

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

DataFormatString

获取或设置字符串,该字符串指定字段值的显示格式。Gets or sets the string that specifies the display format for the value of the field. CheckBoxField 类不支持该属性。This property is not supported by the CheckBoxField class.

DesignMode

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

(继承自 DataControlField)
FooterStyle

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

(继承自 DataControlField)
FooterText

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

(继承自 DataControlField)
HeaderImageUrl

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

(继承自 DataControlField)
HeaderStyle

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

(继承自 DataControlField)
HeaderText

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

(继承自 BoundField)
HtmlEncode

重写 HtmlEncode 属性。Overrides the HtmlEncode property. CheckBoxField 类不支持该属性。This property is not supported by the CheckBoxField class.

HtmlEncodeFormatString

获取或设置一个值,该值指示格式化的文本在显示前是否应经过 HTML 编码。Gets or sets a value that indicates whether the formatted text should be HTML encoded before it is displayed.

InsertVisible

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

(继承自 DataControlField)
IsTrackingViewState

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

(继承自 DataControlField)
ItemStyle

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

(继承自 DataControlField)
NullDisplayText

获取或设置字段值为 null 时为字段显示的文本。Gets or sets the text displayed for a field when the field's value is null. CheckBoxField 类不支持该属性。This property is not supported by the CheckBoxField class.

ReadOnly

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

(继承自 BoundField)
ShowHeader

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

(继承自 DataControlField)
SortExpression

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

(继承自 DataControlField)
SupportsHtmlEncode

获取指示控件是否支持 HTML 编码的布尔值。Gets a Boolean value indicating whether the control supports HTML encoding.

Text

获取或设置要显示在 CheckBoxField 对象中每一个复选框旁边的标题。Gets or sets the caption to display next to each check box in a CheckBoxField object.

ValidateRequestMode

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

(继承自 BoundField)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原 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)
Visible

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

(继承自 DataControlField)

方法

CloneField()

创建当前 DataControlField 派生对象的副本。Creates a duplicate copy of the current DataControlField-derived object.

(继承自 DataControlField)
CopyProperties(DataControlField)

将当前 CheckBoxField 对象的属性复制到指定的 DataControlField 对象。Copies the properties of the current CheckBoxField object to the specified DataControlField object.

CreateField()

创建一个空的 CheckBoxField 对象。Creates an empty CheckBoxField object.

Equals(Object)

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

(继承自 Object)
ExtractValuesFromCell(IOrderedDictionary, DataControlFieldCell, DataControlRowState, Boolean)

使用指定的 IDictionary 对象中的值填充指定的 DataControlFieldCell 对象。Fills the specified IDictionary object with the values from the specified DataControlFieldCell object.

FormatDataValue(Object, Boolean)

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

(继承自 BoundField)
GetDesignTimeValue()

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

GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
GetValue(Control)

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

(继承自 BoundField)
Initialize(Boolean, Control)

初始化 BoundField 对象。Initializes the BoundField object.

(继承自 BoundField)
InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32)

将指定的 TableCell 对象初始化为指定的行状态。Initializes the specified TableCell object to the specified row state.

(继承自 BoundField)
InitializeDataCell(DataControlFieldCell, DataControlRowState)

将指定的 DataControlFieldCell 对象初始化为指定的行状态。Initializes the specified DataControlFieldCell object to the specified row state.

LoadViewState(Object)

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

(继承自 BoundField)
MemberwiseClone()

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

(继承自 Object)
OnDataBindField(Object, EventArgs)

将字段的值绑定到 CheckBoxField 对象中的复选框。Binds the value of a field to a check box in the CheckBoxField object.

OnFieldChanged()

引发 FieldChanged 事件。Raises the FieldChanged event.

(继承自 DataControlField)
SaveViewState()

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

(继承自 DataControlField)
ToString()

返回表示此 DataControlField 对象的字符串。Returns a string that represents this DataControlField object.

(继承自 DataControlField)
TrackViewState()

使 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)
ValidateSupportsCallback()

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

显式界面实现

IDataSourceViewSchemaAccessor.DataSourceViewSchema

获取或设置与此 DataControlField 对象关联的架构。Gets or sets the schema associated with this DataControlField object.

(继承自 DataControlField)
IStateManager.IsTrackingViewState

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

(继承自 DataControlField)
IStateManager.LoadViewState(Object)

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

(继承自 DataControlField)
IStateManager.SaveViewState()

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

(继承自 DataControlField)
IStateManager.TrackViewState()

使 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)

适用于

另请参阅