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>

備註

CheckBoxField 類別是由資料繫結控制項所使用 (例如 GridViewDetailsView) ,以顯示覆選框中的布林資料欄位值。The 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. 如需如何將記錄放入編輯模式的詳細資訊,請參閱包含物件之父控制項的檔集 CheckBoxFieldFor 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 至具有布林資料類型的欄位,或是可由剖析的字串 ParseBecause 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.

您可以設定屬性,以顯示每個核取方塊旁邊的標題 TextYou can display a caption next to each check box by setting the Text property. CheckBoxField當屬性設定為時,資料繫結控制項中會隱藏物件 Visible falseA CheckBoxField object is hidden in a data-bound control when the Visible property is set to false. 若要防止在編輯模式中修改欄位的值,請將屬性設定 ReadOnlytrueTo prevent the value of a field from being modified in edit mode, set the ReadOnly property to true. 在支援插入記錄的資料繫結控制項 (例如 DetailsView 控制項) 中,您可以 CheckBoxField 將屬性設定為,以在插入模式中隱藏物件 InsertVisible falseIn 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.

您可以自訂物件的頁首和頁尾區段 CheckBoxFieldYou can customize the header and footer sections of a CheckBoxField object. 若要在頁首或頁尾區段中顯示標題,請 HeaderText 分別設定或 FooterText 屬性。To display a caption in the header or footer sections, set the HeaderText or FooterText properties, respectively. 您可以藉由設定屬性來顯示影像,而不是在標頭區段中顯示文字 HeaderImageUrlInstead of displaying text in the header section, you can display an image by setting the HeaderImageUrl property. CheckBoxField 屬性設定為,即可在物件中隱藏標頭區段 ShowHeader falseThe 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 DescriptionDescription
ControlStyle 物件之子 Web 服務器控制項的樣式設定 CheckBoxFieldThe style settings for the child Web server controls of the CheckBoxField object.
FooterStyle 物件頁尾區段的樣式設定 CheckBoxFieldThe style settings for the footer section of the CheckBoxField object.
HeaderStyle 物件之標頭區段的樣式設定 CheckBoxFieldThe style settings for the header section of the CheckBoxField object.
ItemStyle 物件中資料項目的樣式設定 CheckBoxFieldThe 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 物件中所包含的控制項是否支援回呼 (Callback)。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)

適用於

另請參閱