GridView 類別

定義

在資料表中顯示資料來源的值,其中每個資料行各代表一個欄位,而每個資料列各代表一項記錄。 GridView 控制項可讓您選取、排序和編輯這些項目。

public ref class GridView : System::Web::UI::WebControls::CompositeDataBoundControl, System::Web::UI::ICallbackEventHandler, System::Web::UI::IPostBackEventHandler, System::Web::UI::WebControls::ICallbackContainer, System::Web::UI::WebControls::IPersistedSelector, System::Web::UI::WebControls::IPostBackContainer
public ref class GridView : System::Web::UI::WebControls::CompositeDataBoundControl, System::Web::UI::ICallbackEventHandler, System::Web::UI::IDataKeysControl, System::Web::UI::IPostBackEventHandler, System::Web::UI::WebControls::ICallbackContainer, System::Web::UI::WebControls::IDataBoundListControl, System::Web::UI::WebControls::IFieldControl, System::Web::UI::WebControls::IPersistedSelector, System::Web::UI::WebControls::IPostBackContainer
[System.Web.UI.ControlValueProperty("SelectedValue")]
public class GridView : System.Web.UI.WebControls.CompositeDataBoundControl, System.Web.UI.ICallbackEventHandler, System.Web.UI.IPostBackEventHandler, System.Web.UI.WebControls.ICallbackContainer, System.Web.UI.WebControls.IPersistedSelector, System.Web.UI.WebControls.IPostBackContainer
[System.Web.UI.ControlValueProperty("SelectedValue")]
public class GridView : System.Web.UI.WebControls.CompositeDataBoundControl, System.Web.UI.ICallbackEventHandler, System.Web.UI.IDataKeysControl, System.Web.UI.IPostBackEventHandler, System.Web.UI.WebControls.ICallbackContainer, System.Web.UI.WebControls.IDataBoundListControl, System.Web.UI.WebControls.IFieldControl, System.Web.UI.WebControls.IPersistedSelector, System.Web.UI.WebControls.IPostBackContainer
[<System.Web.UI.ControlValueProperty("SelectedValue")>]
type GridView = class
    inherit CompositeDataBoundControl
    interface IPostBackContainer
    interface IPostBackEventHandler
    interface ICallbackContainer
    interface ICallbackEventHandler
    interface IPersistedSelector
[<System.Web.UI.ControlValueProperty("SelectedValue")>]
type GridView = class
    inherit CompositeDataBoundControl
    interface IPostBackContainer
    interface IPostBackEventHandler
    interface ICallbackContainer
    interface ICallbackEventHandler
    interface IPersistedSelector
    interface IDataKeysControl
    interface IDataBoundListControl
    interface IDataBoundControl
    interface IFieldControl
Public Class GridView
Inherits CompositeDataBoundControl
Implements ICallbackContainer, ICallbackEventHandler, IPersistedSelector, IPostBackContainer, IPostBackEventHandler
Public Class GridView
Inherits CompositeDataBoundControl
Implements ICallbackContainer, ICallbackEventHandler, IDataBoundListControl, IDataKeysControl, IFieldControl, IPersistedSelector, IPostBackContainer, IPostBackEventHandler
繼承
屬性
實作

範例

有原始程式碼的 Visual Studio 網站專案可隨附本主題: 下載

下列範例示範如何使用 GridView 控制項,在 Microsoft SQL Server 中顯示 AdventureWorksLT 範例資料庫之 Customers 資料表的值。 這些值是使用 SqlDataSource 控制項擷取。

<asp:sqldatasource id="CustomersSource"
  selectcommand="SELECT CustomerID, CompanyName, FirstName, LastName FROM SalesLT.Customer"
  connectionstring="<%$ ConnectionStrings:AWLTConnectionString %>" 
  runat="server"/>

<asp:gridview id="CustomersGridView" 
  datasourceid="CustomersSource" 
  autogeneratecolumns="False"
  emptydatatext="No data available." 
  allowpaging="True" 
  runat="server" DataKeyNames="CustomerID">
    <Columns>
        <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
            InsertVisible="False" ReadOnly="True" SortExpression="CustomerID" />
        <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
            SortExpression="CompanyName" />
        <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
            SortExpression="FirstName" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" 
            SortExpression="LastName" />
    </Columns>
</asp:gridview>
<asp:sqldatasource id="CustomersSource"
  selectcommand="SELECT CustomerID, CompanyName, FirstName, LastName FROM SalesLT.Customer"
  connectionstring="<%$ ConnectionStrings:AWLTConnectionString %>" 
  runat="server"/>

<asp:gridview id="CustomersGridView" 
  datasourceid="CustomersSource" 
  autogeneratecolumns="False"
  emptydatatext="No data available." 
  allowpaging="True" 
  runat="server" DataKeyNames="CustomerID">
    <Columns>
        <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" 
            InsertVisible="False" ReadOnly="True" SortExpression="CustomerID" />
        <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
            SortExpression="CompanyName" />
        <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
            SortExpression="FirstName" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" 
            SortExpression="LastName" />
    </Columns>
</asp:gridview>

下列範例示範如何使用 GridView 控制項和 LinqDataSource 控制項,以便編輯記錄。

<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
    ContextTypeName="AdventureWorksLTDataClassesDataContext"
    EnableDelete="True" EnableInsert="True" EnableUpdate="True" 
    TableName="SalesOrderDetails">
</asp:LinqDataSource>

<asp:GridView ID="GridView1" runat="server" 
    AutoGenerateColumns="False" 
    DataKeyNames="SalesOrderID,SalesOrderDetailID"
    DataSourceID="LinqDataSource1">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" 
            ShowEditButton="True" />
        <asp:BoundField DataField="SalesOrderID" 
            HeaderText="SalesOrderID" ReadOnly="True"
            SortExpression="SalesOrderID" />
        <asp:BoundField DataField="SalesOrderDetailID" 
            HeaderText="SalesOrderDetailID" InsertVisible="False"
            ReadOnly="True" SortExpression="SalesOrderDetailID" />
        <asp:BoundField DataField="OrderQty" 
            HeaderText="OrderQty" SortExpression="OrderQty" />
        <asp:BoundField DataField="ProductID" 
            HeaderText="ProductID" SortExpression="ProductID" />
        <asp:BoundField DataField="UnitPrice" 
            HeaderText="UnitPrice" SortExpression="UnitPrice" />
        <asp:BoundField DataField="ModifiedDate" 
            HeaderText="ModifiedDate" SortExpression="ModifiedDate" />
    </Columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
    ContextTypeName="AdventureWorksLTDataClassesDataContext"
    EnableDelete="True" EnableInsert="True" EnableUpdate="True" 
    TableName="SalesOrderDetails">
</asp:LinqDataSource>

<asp:GridView ID="GridView1" runat="server" 
    AutoGenerateColumns="False" 
    DataKeyNames="SalesOrderID,SalesOrderDetailID"
    DataSourceID="LinqDataSource1">
    <Columns>
        <asp:CommandField ShowDeleteButton="True" 
            ShowEditButton="True" />
        <asp:BoundField DataField="SalesOrderID" 
            HeaderText="SalesOrderID" ReadOnly="True"
            SortExpression="SalesOrderID" />
        <asp:BoundField DataField="SalesOrderDetailID" 
            HeaderText="SalesOrderDetailID" InsertVisible="False"
            ReadOnly="True" SortExpression="SalesOrderDetailID" />
        <asp:BoundField DataField="OrderQty" 
            HeaderText="OrderQty" SortExpression="OrderQty" />
        <asp:BoundField DataField="ProductID" 
            HeaderText="ProductID" SortExpression="ProductID" />
        <asp:BoundField DataField="UnitPrice" 
            HeaderText="UnitPrice" SortExpression="UnitPrice" />
        <asp:BoundField DataField="ModifiedDate" 
            HeaderText="ModifiedDate" SortExpression="ModifiedDate" />
    </Columns>
</asp:GridView>

如需示範如何存取儲存格中值的範例,請參閱 GridViewRow

備註

本主題內容:

簡介

控制項 GridView 用來顯示資料表中資料來源的值。 每個資料行都代表欄位,而每個資料列則代表一筆記錄。 控制項 GridView 支援下列功能:

  • 系結至資料來源控制項,例如 SqlDataSource

  • 內建排序功能。

  • 內建更新和刪除功能。

  • 內建分頁功能。

  • 內建資料列選取功能。

  • 以程式設計方式存取 GridView 物件模型,以動態設定屬性、處理事件等等。

  • 多個索引鍵欄位。

  • 超連結資料行的多個資料欄位。

  • 可透過主題和樣式自訂的外觀。

  • 若要瞭解 ASP.NET 中可用的其他資料繫結控制項,請參閱 資料系結 Web 服務器控制項

注意

如果您熟悉 DataGrid .NET Framework 1.0 版的控制項,控制項 GridView 就是控制項的 DataGrid 後續任務。

資料列欄位

控制項中的每個 GridView 資料行都會以 DataControlField 物件表示。 根據預設, AutoGenerateColumns 屬性會設定為 true ,這會為數據源中的每個欄位建立 AutoGeneratedField 物件。 然後,每個欄位會依每個欄位出現在資料來源的順序, GridView 轉譯為 控制項中的資料行。

您也可以將 屬性設定 AutoGenerateColumnsfalse ,然後定義您自己的資料列欄位集合,手動控制控制項中顯示的 GridView 資料列欄位。 不同的資料列欄位類型會決定 控制項中資料行的行為。 下表列出可使用的不同資料列欄位類型。

資料列欄位類型 描述
BoundField 顯示資料來源中欄位的值。 這是 控制項的預設資料行類型 GridView
ButtonField 顯示 控制項中 GridView 每個專案的命令按鈕。 這可讓您建立自訂按鈕控制項的資料行,例如 [新增] 或 [移除] 按鈕。
CheckBoxField 顯示 控制項中 GridView 每個專案的核取方塊。 此資料列欄位類型通常用來顯示具有布林值的欄位。
CommandField 顯示預先定義的命令按鈕,以執行選取、編輯或刪除作業。
HyperLinkField 將資料來源中的欄位值顯示為超連結。 此資料列欄位類型可讓您將第二個欄位系結至超連結的 URL。
ImageField 顯示 控制項中 GridView 每個專案的影像。
TemplateField 根據指定的範本,顯示 控制項中 GridView 每個專案的使用者定義內容。 此資料列欄位類型可讓您建立自訂資料列欄位。

若要以宣告方式定義資料列欄位集合,請先在控制項的開頭和結束記號之間加入開頭和結尾 <Columns> 標記 GridView 。 接下來,列出您要在開頭和結尾 <Columns> 標記之間包含的資料列欄位。 指定的資料行會依列出的順序新增至 Columns 集合。 集合 Columns 會儲存 控制項中的所有資料列欄位,並可讓您以程式設計方式管理 控制項中的資料 GridView 列欄位。

明確宣告的資料列欄位可以與自動產生的資料列欄位搭配顯示。 使用這兩個欄位時,會先轉譯明確宣告的資料列欄位,後面接著自動產生的資料列欄位。

注意

自動產生的資料列欄位不會新增至 Columns 集合。

系結至資料

GridView控制項可以系結至資料來源控制項 (例如 SqlDataSource 控制項或 ObjectDataSource 控制項) ,或實作 System.Collections.IEnumerable 介面的任何資料來源集合,例如 System.Data.DataViewSystem.Collections.ArrayListSystem.Collections.Generic.List<T> 或其他集合類型。 使用下列其中一種方法,將 GridView 控制項系結至適當的資料來源類型:

  • 若要系結至資料來源控制項,請將 DataSourceID 控制項的 GridView 屬性設定為 ID 資料來源控制項的值。 控制項 GridView 會自動系結至指定的資料來源控制項,並可以利用資料來源控制項的功能來執行排序、更新、刪除和分頁。 這是系結至資料的慣用方法。

  • 若要系結至實作 介面的 System.Collections.IEnumerable 資料來源,請以程式設計方式將 DataSource 控制項的 GridView 屬性設定為數據源,然後呼叫 DataBind 方法。 使用此方法時, GridView 控制項不會提供內建的排序、更新、刪除和分頁功能。 您必須使用適當的事件來提供這項功能。

如需資料系結的詳細資訊,請參閱 ASP.NET 資料存取內容對應

注意

此控制項可用來顯示使用者輸入,其中可能包含惡意用戶端腳本。 檢查從用戶端傳送的任何資訊,以取得可執行腳本、SQL 語句或其他程式碼,再將其顯示在應用程式中。 可能的話,強烈建議在值顯示于此控制項之前先進行 HTML 編碼, (BoundField 預設為 HTML 編碼值的類別) 。 ASP.NET 提供輸入要求驗證功能,以封鎖使用者輸入中的腳本和 HTML。 也會提供驗證服務器控制項來評估使用者輸入。 如需詳細資訊,請參閱 驗證控制項簡介

資料作業

控制項 GridView 提供許多內建功能,可讓使用者排序、更新、刪除、選取和逐頁查看控制項中的專案。 當 GridView 控制項系結至資料來源控制項時, GridView 控制項可以利用資料來源控制項的功能,並提供自動排序、更新和刪除功能。

注意

控制項 GridView 可以支援使用其他類型的資料來源進行排序、更新和刪除。 不過,您必須為這些作業提供適當的事件處理常式實作。

排序可讓使用者按一下資料行的標頭,來排序控制項中 GridView 與特定資料行相關的專案。 若要啟用排序,請將 AllowSorting 屬性設定為 true

當 或 TemplateField 資料列欄位中的按鈕 ButtonField 分別具有 「Edit」、「Delete」 和 「Select」 的命令名稱時,就會啟用自動更新、刪除和選取功能。 如果 AutoGenerateEditButton 、 或 AutoGenerateSelectButton 屬性分別設定為 trueAutoGenerateDeleteButton 控制項 GridView 可以使用 [編輯]、[刪除] 或 [選取] 按鈕自動加入 CommandField 資料列欄位。

注意

控制項不支援 GridView 將記錄插入資料來源。 不過,您可以使用 控制項搭配 DetailsViewFormView 控制項來插入記錄 GridView 。 如需詳細資訊,請參閱 DetailsViewFormView

控制項可以自動將記錄分成分頁, GridView 而不是同時顯示資料來源中的所有記錄。 若要啟用分頁,請將 AllowPaging 屬性設定為 true

注意

控制項 GridView 會根據儲存在 中 ViewState 的資訊,在回傳時重新建立。 GridView如果控制項包含 TemplateFieldCommandField 屬性設定為 trueCausesValidation ,則 EnableViewState 屬性也必須設定為 true ,以確保同時執行更新和刪除等資料作業,套用至適當的資料列。

自訂使用者介面

您可以為控制項的不同部分設定樣式屬性,以自訂控制項的外觀 GridView 。 下表列出不同的樣式屬性。

Style 屬性 描述
AlternatingRowStyle 控制項中替代資料列的 GridView 樣式設定。 設定此屬性時,資料列會顯示在設定與 AlternatingRowStyle 設定之間 RowStyle 交替。
EditRowStyle 控制項中編輯之資料列的 GridView 樣式設定。
EmptyDataRowStyle 當資料來源不包含任何記錄時,控制項中顯示的 GridView 空白資料列樣式設定。
FooterStyle 控制項頁尾資料列的 GridView 樣式設定。
HeaderStyle 控制項標題列的 GridView 樣式設定。
PagerStyle 控制項之呼叫器資料列的 GridView 樣式設定。
RowStyle 控制項中資料列的 GridView 樣式設定。 AlternatingRowStyle同時設定 屬性時,資料列會顯示在設定與 AlternatingRowStyle 設定之間 RowStyle 交替。
SelectedRowStyle 控制項中所選資料列的 GridView 樣式設定。
SortedAscendingCellStyle 資料行的樣式設定,資料會在 控制項中 GridView 排序依據。 設定此樣式時,當資料以遞增順序排序時,會套用醒目提示資料行) 的樣式 (。
SortedAscendingHeaderStyle 資料行的樣式設定,資料會在 控制項中 GridView 排序依據。 設定此樣式時,當資料以遞增順序排序時,資料會以遞增順序排序時,將資料遞增放在控制項的 GridView 標頭上。
SortedDescendingCellStyle 資料行的樣式設定,資料會在 控制項中 GridView 排序依據。 設定此樣式時,當資料以遞減順序排序時,會將醒目提示的資料行) 套用至儲存格的樣式 (。
SortedDescendingHeaderStyle 資料行的樣式設定,資料會在 控制項中 GridView 排序依據。 設定此樣式時,當資料以遞減順序排序時,會將指向向下箭號的箭號放在 的 GridView 標頭上。

您也可以顯示或隱藏控制項的不同部分。 下表列出控制要顯示或隱藏哪些元件的屬性。

屬性 描述
ShowFooter 顯示或隱藏 控制項的 GridView 頁尾區段。
ShowHeader 顯示或隱藏 控制項的 GridView 標頭區段。

事件

控制項 GridView 提供數個您可以針對的事件進行程式設計。 這可讓您在事件發生時執行自訂常式。 下表列出 控制項所支援 GridView 的事件。

事件 描述
PageIndexChanged 按一下其中一個頁面巡覽區按鈕時發生 (但在 GridView 控制項處理分頁作業之後)。 當您需要在使用者流覽至控制項中的不同頁面之後執行工作時,通常會使用此事件。
PageIndexChanging 發生於按一下其中一個頁面巡覽區按鈕時,但是在 GridView 控制項處理分頁作業之前。 此事件通常用來取消分頁作業。
RowCancelingEdit 發生于按一下資料列的 [取消] 按鈕,但在控制項結束編輯模式之前 GridView 。 此事件通常用來停止取消作業。
RowCommand 按一下 GridView 控制項中的按鈕時會發生這個事件。 此事件通常用於在控制項中按一下按鈕時執行工作。
RowCreated 發生于 控制項中 GridView 建立新資料列時。 建立資料列時,通常會使用此事件來修改資料列的內容。
RowDataBound 發生于資料列系結至 控制項中的資料 GridView 時。 當資料列系結至資料時,通常會使用此事件來修改資料列的內容。
RowDeleted 發生于按一下資料列的 [刪除] 按鈕時,但在控制項從資料來源中刪除記錄之後 GridView 。 此事件通常用來檢查刪除作業的結果。
RowDeleting 發生于按一下資料列的 [刪除] 按鈕時,但在控制項從資料來源中刪除記錄之前 GridView 。 此事件通常用來取消刪除作業。
RowEditing 按一下資料列的 [編輯] 按鈕時發生 (但在 GridView 控制項進入編輯模式之前)。 此事件通常用來取消編輯作業。
RowUpdated 按一下資料列的 [更新] 按鈕時發生 (但在 GridView 控制項更新資料列之後)。 此事件通常用來檢查更新作業的結果。
RowUpdating 按一下資料列的 [更新] 按鈕時發生 (但在 GridView 控制項更新資料列之前)。 此事件通常用來取消更新作業。
SelectedIndexChanged 按一下資料列的 [選取] 按鈕時發生 (但在 GridView 控制項處理選取作業之後)。 這個事件通常用來在控制項中選取資料列之後執行工作。
SelectedIndexChanging 按一下資料列的 [選取] 按鈕時發生 (但在 GridView 控制項處理選取作業之前)。 此事件通常用來取消選取作業。
Sorted 按一下排序資料行的超連結時發生 (但在 GridView 控制項處理排序作業之後)。 此事件通常用來在使用者按一下超連結來排序資料行之後執行工作。
Sorting 按一下排序資料行的超連結時發生 (但在 GridView 控制項處理排序作業之前)。 此事件通常用來取消排序作業或執行自訂排序常式。

Accessibility

如需如何設定此控制項以產生符合協助工具標準的標記的相關資訊,請參閱 Visual Studio 中的協助工具,以及 ASP.NETASP.NET 控制項和協助工具

宣告式語法

<asp:GridView  
    AccessKey="string"  
    AllowPaging="True|False"  
    AllowSorting="True|False"  
    AutoGenerateColumns="True|False"  
    AutoGenerateDeleteButton="True|False"  
    AutoGenerateEditButton="True|False"  
    AutoGenerateSelectButton="True|False"  
    BackColor="color name|#dddddd"  
    BackImageUrl="uri"  
    BorderColor="color name|#dddddd"  
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|  
        Inset|Outset"  
    BorderWidth="size"  
    Caption="string"  
    CaptionAlign="NotSet|Top|Bottom|Left|Right"  
    CellPadding="integer"  
    CellSpacing="integer"  
    CssClass="string"  
    DataKeyNames="string"  
    DataMember="string"  
    DataSource="string"  
    DataSourceID="string"  
    EditIndex="integer"  
    EmptyDataText="string"  
    Enabled="True|False"  
    EnableSortingAndPagingCallbacks="True|False"  
    EnableTheming="True|False"  
    EnableViewState="True|False"  
    Font-Bold="True|False"  
    Font-Italic="True|False"  
    Font-Names="string"  
    Font-Overline="True|False"  
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|  
        Large|X-Large|XX-Large"  
    Font-Strikeout="True|False"  
    Font-Underline="True|False"  
    ForeColor="color name|#dddddd"  
    GridLines="None|Horizontal|Vertical|Both"  
    Height="size"  
    HorizontalAlign="NotSet|Left|Center|Right|Justify"  
    ID="string"  
    OnDataBinding="DataBinding event handler"  
    OnDataBound="DataBound event handler"  
    OnDisposed="Disposed event handler"  
    OnInit="Init event handler"  
    OnLoad="Load event handler"  
    OnPageIndexChanged="PageIndexChanged event handler"  
    OnPageIndexChanging="PageIndexChanging event handler"  
    OnPreRender="PreRender event handler"  
    OnRowCancelingEdit="RowCancelingEdit event handler"  
    OnRowCommand="RowCommand event handler"  
    OnRowCreated="RowCreated event handler"  
    OnRowDataBound="RowDataBound event handler"  
    OnRowDeleted="RowDeleted event handler"  
    OnRowDeleting="RowDeleting event handler"  
    OnRowEditing="RowEditing event handler"  
    OnRowUpdated="RowUpdated event handler"  
    OnRowUpdating="RowUpdating event handler"  
    OnSelectedIndexChanged="SelectedIndexChanged event handler"  
    OnSelectedIndexChanging="SelectedIndexChanging event handler"  
    OnSorted="Sorted event handler"  
    OnSorting="Sorting event handler"  
    OnUnload="Unload event handler"  
    PageIndex="integer"  
    PagerSettings-FirstPageImageUrl="uri"  
    PagerSettings-FirstPageText="string"  
    PagerSettings-LastPageImageUrl="uri"  
    PagerSettings-LastPageText="string"  
    PagerSettings-Mode="NextPrevious|Numeric|NextPreviousFirstLast|  
        NumericFirstLast"  
    PagerSettings-NextPageImageUrl="uri"  
    PagerSettings-NextPageText="string"  
    PagerSettings-PageButtonCount="integer"  
    PagerSettings-Position="Bottom|Top|TopAndBottom"  
    PagerSettings-PreviousPageImageUrl="uri"  
    PagerSettings-PreviousPageText="string"  
    PagerSettings-Visible="True|False"  
    PageSize="integer"  
    RowHeaderColumn="string"  
    runat="server"  
    SelectedIndex="integer"  
    ShowFooter="True|False"  
    ShowHeader="True|False"  
    SkinID="string"  
    Style="string"  
    TabIndex="integer"  
    ToolTip="string"  
    UseAccessibleHeader="True|False"  
    Visible="True|False"  
    Width="size"  
>  
        <AlternatingRowStyle />  
        <Columns>  
                <asp:BoundField  
                    AccessibleHeaderText="string"  
                    ApplyFormatInEditMode="True|False"  
                    ConvertEmptyStringToNull="True|False"  
                    DataField="string"  
                    DataFormatString="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    HtmlEncode="True|False"  
                    InsertVisible="True|False"  
                    NullDisplayText="string"  
                    ReadOnly="True|False"  
                    ShowHeader="True|False"  
                    SortExpression="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:BoundField>  
                <asp:ButtonField  
                    AccessibleHeaderText="string"  
                    ButtonType="Button|Image|Link"  
                    CausesValidation="True|False"  
                    CommandName="string"  
                    DataTextField="string"  
                    DataTextFormatString="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    ImageUrl="uri"  
                    InsertVisible="True|False"  
                    ShowHeader="True|False"  
                    SortExpression="string"  
                    Text="string"  
                    ValidationGroup="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:ButtonField>  
                <asp:CheckBoxField  
                    AccessibleHeaderText="string"  
                    DataField="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    InsertVisible="True|False"  
                    ReadOnly="True|False"  
                    ShowHeader="True|False"  
                    SortExpression="string"  
                    Text="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:CheckBoxField>  
                <asp:CommandField  
                    AccessibleHeaderText="string"  
                    ButtonType="Button|Image|Link"  
                    CancelImageUrl="uri"  
                    CancelText="string"  
                    CausesValidation="True|False"  
                    DeleteImageUrl="uri"  
                    DeleteText="string"  
                    EditImageUrl="uri"  
                    EditText="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    InsertImageUrl="uri"  
                    InsertText="string"  
                    InsertVisible="True|False"  
                    NewImageUrl="uri"  
                    NewText="string"  
                    SelectImageUrl="uri"  
                    SelectText="string"  
                    ShowCancelButton="True|False"  
                    ShowDeleteButton="True|False"  
                    ShowEditButton="True|False"  
                    ShowHeader="True|False"  
                    ShowInsertButton="True|False"  
                    ShowSelectButton="True|False"  
                    SortExpression="string"  
                    UpdateImageUrl="uri"  
                    UpdateText="string"  
                    ValidationGroup="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:CommandField>  
                <asp:DynamicField  
                    AccessibleHeaderText="string"  
                    ApplyFormatInEditMode="True|False"  
                    ConvertEmptyStringToNull="True|False"  
                    DataField="string"  
                    DataFormatString="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    HtmlEncode="True|False"  
                    InsertVisible="True|False"  
                    NullDisplayText="string"  
                    ShowHeader="True|False"  
                    UIHint="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:DynamicField>  
                <asp:HyperLinkField  
                    AccessibleHeaderText="string"  
                    DataNavigateUrlFields="string"  
                    DataNavigateUrlFormatString="string"  
                    DataTextField="string"  
                    DataTextFormatString="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    InsertVisible="True|False"  
                    NavigateUrl="uri"  
                    ShowHeader="True|False"  
                    SortExpression="string"  
                    Target="string|_blank|_parent|_search|_self|_top"  
                    Text="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:HyperLinkField>  
                <asp:ImageField  
                    AccessibleHeaderText="string"  
                    AlternateText="string"  
                    ConvertEmptyStringToNull="True|False"  
                    DataAlternateTextField="string"  
                    DataAlternateTextFormatString="string"  
                    DataImageUrlField="string"  
                    DataImageUrlFormatString="string"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    InsertVisible="True|False"  
                    NullDisplayText="string"  
                    NullImageUrl="uri"  
                    ReadOnly="True|False"  
                    ShowHeader="True|False"  
                    SortExpression="string"  
                    Visible="True|False"  
>  
                        <ControlStyle />  
                        <FooterStyle />  
                        <HeaderStyle />  
                        <ItemStyle />  
                </asp:ImageField>  
                <asp:TemplateField  
                    AccessibleHeaderText="string"  
                    ConvertEmptyStringToNull="True|False"  
                    FooterText="string"  
                    HeaderImageUrl="uri"  
                    HeaderText="string"  
                    InsertVisible="True|False"  
                    ShowHeader="True|False"  
                    SortExpression="string"  
                    Visible="True|False"  
>  
                            <ControlStyle />  
                            <FooterStyle />  
                            <HeaderStyle />  
                            <ItemStyle />  
                        <AlternatingItemTemplate>  
                            <!-- child controls -->  
                        </AlternatingItemTemplate>  
                        <EditItemTemplate>  
                            <!-- child controls -->  
                        </EditItemTemplate>  
                        <FooterTemplate>  
                            <!-- child controls -->  
                        </FooterTemplate>  
                        <HeaderTemplate>  
                            <!-- child controls -->  
                        </HeaderTemplate>  
                        <InsertItemTemplate>  
                            <!-- child controls -->  
                        </InsertItemTemplate>  
                        <ItemTemplate>  
                            <!-- child controls -->  
                        </ItemTemplate>  
                </asp:TemplateField>  
        </Columns>  
        <EditRowStyle />  
        <EmptyDataRowStyle />  
        <EmptyDataTemplate>  
            <!-- child controls -->  
        </EmptyDataTemplate>  
        <FooterStyle />  
        <HeaderStyle />  
        <PagerSettings  
            FirstPageImageUrl="uri"  
            FirstPageText="string"  
            LastPageImageUrl="uri"  
            LastPageText="string"  
            Mode="NextPrevious|Numeric|NextPreviousFirstLast|  
                NumericFirstLast"  
            NextPageImageUrl="uri"  
            NextPageText="string"  
            OnPropertyChanged="PropertyChanged event handler"  
            PageButtonCount="integer"  
            Position="Bottom|Top|TopAndBottom"  
            PreviousPageImageUrl="uri"  
            PreviousPageText="string"  
            Visible="True|False"  
        />  
        <PagerStyle />  
        <PagerTemplate>  
            <!-- child controls -->  
        </PagerTemplate>  
        <RowStyle />  
        <SelectedRowStyle />  
</asp:GridView>  

建構函式

GridView()

初始化 GridView 類別的新執行個體。

屬性

AccessKey

取得或設定便捷鍵 (Access Key),可讓您快速巡覽至 Web 伺服器控制項。

(繼承來源 WebControl)
Adapter

針對控制項取得瀏覽器的特定配置器。

(繼承來源 Control)
AllowCustomPaging

取得或設定值,指出是否啟用自訂分頁。

AllowPaging

取得或設定值,指出是否啟用分頁功能。

AllowSorting

取得或設定值,指出是否啟用排序功能。

AlternatingRowStyle

取得 TableItemStyle 物件的參考,可讓您設定 GridView 控制項中替代資料列的外觀。

AppRelativeTemplateSourceDirectory

取得或設定包含了此控制項之 PageUserControl 物件的相對應用程式虛擬目錄。

(繼承來源 Control)
Attributes

取得任意屬性 (Attribute) 的集合 (只供呈現),不與控制項上的屬性 (Property) 對應。

(繼承來源 WebControl)
AutoGenerateColumns

取得或設定值,指出是否自動建立資料來源中每個欄位的繫結欄位。

AutoGenerateDeleteButton

取得或設定值,指出是否會將具有每個資料列之 [刪除] 按鈕的 CommandField 欄位資料行自動加入至 GridView 控制項。

AutoGenerateEditButton

取得或設定值,指出是否會將具有每個資料列之 [編輯] 按鈕的 CommandField 欄位資料行自動加入至 GridView 控制項。

AutoGenerateSelectButton

取得或設定值,指出是否會將具有每個資料列之 [選取] 按鈕的 CommandField 欄位資料行自動加入至 GridView 控制項。

BackColor

取得或設定 Web 伺服器控制項的背景色彩。

(繼承來源 WebControl)
BackImageUrl

取得或設定要顯示於 GridView 控制項背景之影像的 URL。

BindingContainer

取得包含了此控制項之資料繫結的控制項。

(繼承來源 Control)
BorderColor

取得或設定 Web 控制項的框線色彩。

(繼承來源 WebControl)
BorderStyle

取得或設定 Web 伺服器控制項的框線樣式。

(繼承來源 WebControl)
BorderWidth

取得或設定 Web 伺服器控制項的框線寬度。

(繼承來源 WebControl)
BottomPagerRow

取得 GridViewRow 物件,其表示 GridView 控制項中的底端頁面巡覽列。

Caption

取得或設定要在 GridView 控制項之 HTML 標題項目中呈現的文字。 這個屬性可讓協助技術裝置的使用者更容易存取控制項。

CaptionAlign

取得或設定 GridView 控制項中 HTML 標題項目的水平或垂直位置。 這個屬性可讓協助技術裝置的使用者更容易存取控制項。

CellPadding

取得或設定儲存格內容和其框線之間的間距。

CellSpacing

取得或設定儲存格之間的間距。

ChildControlsCreated

取得值,指出是否已經建立伺服器控制項的子控制項。

(繼承來源 Control)
ClientID

取得 ASP.NET 所產生之 HTML 標記的控制項識別碼。

(繼承來源 Control)
ClientIDMode

取得或設定用來產生 ClientID 屬性值的演算法。

(繼承來源 Control)
ClientIDRowSuffix

取得或設定資料欄位的名稱,這些值會附加至 ClientID 屬性,以便識別資料繫結控制項的每一個唯一的執行個體。

ClientIDRowSuffixDataKeys

取得資料值,這些值會在 ASP.NET 產生 ClientID 值時,用來識別資料繫結控制項的每個唯一的執行個體。

ClientIDSeparator

取得字元值,表示在 ClientID 屬性中所使用的分隔字元。

(繼承來源 Control)
Columns

取得 DataControlField 物件的集合,其表示 GridView 控制項中的資料行欄位。

ColumnsGenerator

取得或設定控制項,這個控制項將自動針對使用 ASP.NET 動態資料功能的 GridView 控制項產生資料行。

Context

取得與目前 Web 要求的伺服器控制項關聯的 HttpContext 物件。

(繼承來源 Control)
Controls

取得複合資料繫結控制項內之子控制項的集合。

(繼承來源 CompositeDataBoundControl)
ControlStyle

取得 Web 伺服器控制項的樣式。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
ControlStyleCreated

取得值,指出 Style 物件是否已經為 ControlStyle 屬性建立。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。

(繼承來源 WebControl)
DataItemContainer

如果命名容器實作 IDataItemContainer,則取得命名容器的參考。

(繼承來源 Control)
DataKeyNames

取得或設定陣列,這個陣列包含 GridView 控制項中所顯示項目的主索引鍵欄位名稱。

DataKeys

取得 DataKey 物件的集合,其表示 GridView 控制項中每個資料列的資料索引鍵值。

DataKeysContainer

如果命名容器實作 IDataKeysControl,則取得命名容器的參考。

(繼承來源 Control)
DataMember

取得或設定資料繫結控制項繫結至的資料清單名稱 (如果資料來源包含多個不同資料項目清單)。

(繼承來源 DataBoundControl)
DataSource

取得或設定資料繫結控制項從中擷取其資料項目清單的物件。

(繼承來源 BaseDataBoundControl)
DataSourceID

取得或設定控制項的識別碼,資料繫結控制項會由此擷取其項目清單。

(繼承來源 DataBoundControl)
DataSourceObject

取得物件,這個物件會實作可提供物件資料內容之存取權的 IDataSource 介面。

(繼承來源 DataBoundControl)
DeleteMethod

為了刪除資料,取得或設定要呼叫的方法名稱。

DeleteMethod

為了刪除資料,取得或設定要呼叫的方法名稱。

(繼承來源 CompositeDataBoundControl)
DesignMode

取得值,指出控制項是否正用於設計介面上。

(繼承來源 Control)
EditIndex

取得或設定要編輯之資料列的索引。

EditRowStyle

取得 TableItemStyle 物件的參考,其可讓您設定 GridView 控制項中已選取用於編輯之資料列的外觀。

EmptyDataRowStyle

取得 TableItemStyle 物件的參考,其可讓您設定在 GridView 控制項繫結至不包含任何資料錄的資料來源時所呈現之空白資料列的外觀。

EmptyDataTemplate

取得或設定空白資料之使用者定義的內容,該資料列呈現於 GridView 控制項繫結至不包含任何資料錄的資料來源時。

EmptyDataText

取得或設定空白資料列中顯示的文字,該資料列呈現於 GridView 控制項繫結至不包含任何資料錄的資料來源時。

Enabled

取得或設定值,指出 Web 伺服器控制項是否啟用。

(繼承來源 WebControl)
EnableModelValidation

取得或設定值,這個值表示驗證程式控制項是否要處理在插入或更新作業期間發生的例外狀況。

EnablePersistedSelection

取得或設定值,指出是根據索引還是資料索引鍵值來選取資料列。

EnableSortingAndPagingCallbacks

取得或設定值,指出用戶端回呼是否用於排序和分頁作業。

EnableTheming

取得或設定值,指出佈景主題是否套用至此控制項。

(繼承來源 WebControl)
EnableViewState

取得或設定值,該值表示伺服器控制項是否對要求的用戶端而言保持其檢視狀態,以及它包含的任何子控制項狀態。

(繼承來源 Control)
Events

取得控制項事件處理常式委派 (Delegate) 的清單。 這個屬性是唯讀的。

(繼承來源 Control)
Font

取得與 Web 伺服器控制項關聯的字型屬性。

(繼承來源 WebControl)
FooterRow

取得 GridViewRow 物件,其表示 GridView 控制項中的頁尾資料列。

FooterStyle

取得 TableItemStyle 物件的參考,其可讓您設定 GridView 控制項中頁尾 (Footer) 資料列的外觀。

ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。

(繼承來源 WebControl)
GridLines

取得或設定 GridView 控制項的格線樣式。

HasAttributes

取得值,指出控制項是否已經設定屬性。

(繼承來源 WebControl)
HasChildViewState

取得值,指出目前伺服器控制項的子控制項是否有任何已儲存的檢視狀態設定。

(繼承來源 Control)
HeaderRow

取得 GridViewRow 物件,表示 GridView 控制項中的標頭資料列。

HeaderStyle

取得 TableItemStyle 物件的參考,其可讓您設定 GridView 控制項之標頭資料列的外觀。

Height

取得或設定 Web 伺服器控制項的高度。

(繼承來源 WebControl)
HorizontalAlign

取得或設定頁面上 GridView 控制項的水平對齊。

ID

取得或設定指派給伺服器控制項的程式設計識別項。

(繼承來源 Control)
IdSeparator

取得用來分隔控制項識別項的字元。

(繼承來源 Control)
Initialized

取得值,指出是否已初始化資料繫結控制項。

(繼承來源 BaseDataBoundControl)
InsertMethod

為了插入資料,取得或設定要呼叫的方法名稱。

(繼承來源 CompositeDataBoundControl)
IsBoundUsingDataSourceID

取得值,指出是否已設定 DataSourceID 屬性。

(繼承來源 BaseDataBoundControl)
IsChildControlStateCleared

取得值,指出這個控制項中所包含的控制項是否有控制項狀態。

(繼承來源 Control)
IsDataBindingAutomatic

取得值,指出資料繫結是否為自動。

(繼承來源 BaseDataBoundControl)
IsEnabled

取得值,指出是否啟用控制項。

(繼承來源 WebControl)
IsTrackingViewState

取得值,指出伺服器控制項是否正在儲存檢視狀態的變更。

(繼承來源 Control)
IsUsingModelBinders

取得值,指出模型繫結是否正在使用。

(繼承來源 CompositeDataBoundControl)
IsViewStateEnabled

取得值,指出這個控制項是否已啟用檢視狀態。

(繼承來源 Control)
ItemType

取得或設定強型別資料繫結的資料項目型別名稱。

(繼承來源 DataBoundControl)
LoadViewStateByID

取得值,指出控制項是否依 ID (而不是索引) 參與載入其檢視狀態。

(繼承來源 Control)
NamingContainer

取得伺服器控制項命名容器的參考,其建立唯一命名空間,在具有相同 ID 屬性值的伺服器控制項之間作區別。

(繼承來源 Control)
Page

取得含有伺服器控制項的 Page 執行個體的參考。

(繼承來源 Control)
PageCount

取得 GridView 控制項中顯示資料來源之資料錄所需要的頁數。

PageIndex

取得或設定目前顯示頁面的索引。

PagerSettings

取得 PagerSettings 物件的參考,其可讓您設定 GridView 控制項中頁面巡覽區按鈕的屬性。

PagerStyle

取得 TableItemStyle 物件的參考,其可讓您設定 GridView 控制項之頁面巡覽區資料列的外觀。

PagerTemplate

取得或設定 GridView 控制項中頁面巡覽列的自訂內容。

PageSize

取得或設定 GridView 控制項之頁面上顯示的資料錄數。

Parent

在網頁控制階層架構中取得伺服器控制項之父控制項的參考。

(繼承來源 Control)
RenderingCompatibility

取得值,這個值會指定將與呈現 HTML 相容的 ASP.NET 版本。

(繼承來源 Control)
RequiresDataBinding

取得或設定值,指出是否應該呼叫 DataBind() 方法。

(繼承來源 BaseDataBoundControl)
RowHeaderColumn

取得或設定資料行的名稱,做為 GridView 控制項的資料行行首。 這個屬性可讓協助技術裝置的使用者更容易存取控制項。

Rows

取得 GridViewRow 物件的集合,其表示 GridView 控制項中的資料列。

RowStyle

取得 TableItemStyle 物件的參考,其可讓您設定 GridView 控制項中資料列的外觀。

SelectArguments

取得 DataSourceSelectArguments 物件,當從資料來源控制項擷取資料時資料繫結控制項會使用它。

(繼承來源 DataBoundControl)
SelectedDataKey

取得 DataKey 物件,其包含 GridView 控制項中已選取資料列的資料索引鍵值。

SelectedIndex

取得或設定 GridView 控制項中已選取資料列的索引。

SelectedPersistedDataKey

GridView 控制項中持續選取的項目取得或設定資料索引鍵值。

SelectedRow

取得 GridViewRow 物件的參考,其表示控制項中已選取的資料列。

SelectedRowStyle

取得 TableItemStyle 物件的參考,其可讓您設定 GridView 控制項中已選取資料列的外觀。

SelectedValue

取得 GridView 控制項中已選取資料列的資料索引鍵值。

SelectMethod

為了讀取資料要呼叫的方法的名稱。

(繼承來源 DataBoundControl)
ShowFooter

取得或設定值,指出是否在 GridView 控制項中顯示頁尾資料列。

ShowHeader

取得或設定值,指出是否在 GridView 控制項中顯示標頭資料列。

ShowHeaderWhenEmpty

取得或設定值,這個值表示是否要在 GridView 控制項中的資料行未包含資料時,顯示資料行的標題。

Site

當呈現在設計介面上時,取得裝載目前控制項之容器的資訊。

(繼承來源 Control)
SkinID

取得或設定要套用至控制項的面板。

(繼承來源 WebControl)
SortDirection

取得正在排序之資料行的排序方向。

SortedAscendingCellStyle

取得或設定以遞增順序排序 GridView 資料行時,資料行的 CSS 樣式。

SortedAscendingHeaderStyle

取得或設定以遞增順序排序 GridView 資料行時,要套用至資料行標題的 CSS 樣式。

SortedDescendingCellStyle

取得或設定以遞減順序排序 GridView 資料行時,資料行的樣式。

SortedDescendingHeaderStyle

取得或設定以遞減順序排序 GridView 資料行時,要套用至資料行標題的樣式。

SortExpression

取得與正在排序之資料行關聯的排序運算式。

Style

取得文字屬性的集合,將呈現為 Web 伺服器控制項的外部標記上的樣式屬性。

(繼承來源 WebControl)
SupportsDisabledAttribute

取得值,這個值表示當控制項的 disabled 屬性為 IsEnabled 時,控制項是否應該將呈現之 HTML 項目的 false 屬性設為 "disabled"。

(繼承來源 BaseDataBoundControl)
TabIndex

取得或設定 Web 伺服器控制項的定位索引。

(繼承來源 WebControl)
TagKey

取得 GridView 控制項的 HtmlTextWriterTag 值。

TagName

取得控制項標記的名稱。 這個屬性主要由控制項開發人員使用。

(繼承來源 WebControl)
TemplateControl

取得或設定包含了此控制項之樣板的參考。

(繼承來源 Control)
TemplateSourceDirectory

取得包含目前伺服器控制項的 PageUserControl 的虛擬目錄。

(繼承來源 Control)
ToolTip

取得或設定當滑鼠指標停留在 Web 伺服器控制項時顯示的文字。

(繼承來源 WebControl)
TopPagerRow

取得 GridViewRow 物件,其表示 GridView 控制項中的頂端頁面巡覽列。

UniqueID

取得伺服器控制項唯一的、符合階層架構的識別項。

(繼承來源 Control)
UpdateMethod

為了更新資料,取得或設定要呼叫的方法名稱。

UpdateMethod

為了更新資料,取得或設定要呼叫的方法名稱。

(繼承來源 CompositeDataBoundControl)
UseAccessibleHeader

取得或設定值,指出 GridView 控制項是否以可存取格式呈現其標頭。 這個屬性可讓協助技術裝置的使用者更容易存取控制項。

ValidateRequestMode

取得或設定值,指出控制項是否對來自瀏覽器的用戶端輸入檢查潛在的危險值。

(繼承來源 Control)
ViewState

取得狀態資訊的字典,允許您在相同網頁的多個要求之間,儲存和還原伺服器控制項的檢視狀態。

(繼承來源 Control)
ViewStateIgnoresCase

取得值,指出 StateBag 物件是否不區分大小寫。

(繼承來源 Control)
ViewStateMode

取得或設定這個控制項的檢視狀態模式。

(繼承來源 Control)
VirtualItemCount

取得或設定使用自訂分頁時,GridView 控制項所繫結之資料來源中項目的虛擬數目。

Visible

取得或設定值,指出伺服器控制項是否會轉譯為頁面上的 UI。

(繼承來源 Control)
Width

取得或設定 Web 伺服器控制項的寬度。

(繼承來源 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriterTag 中。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
AddedControl(Control, Int32)

在子控制項加入 Control 物件的 Controls 集合後呼叫。

(繼承來源 Control)
AddParsedSubObject(Object)

通知伺服器控制項,XML 或 HTML 項目已剖析,並將項目加入伺服器控制項的 ControlCollection 物件中。

(繼承來源 Control)
ApplyStyle(Style)

將指定樣式的任何非空白項目加入到 Web 控制項中,覆寫控制項的任何現有的樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ApplyStyleSheetSkin(Page)

將頁面樣式表中所定義的樣式屬性套用至控制項。

(繼承來源 Control)
BeginRenderTracing(TextWriter, Object)

開始進行轉譯資料的設計階段追蹤。

(繼承來源 Control)
BuildProfileTree(String, Boolean)

收集伺服器控制項的相關資訊,並在頁面啟用追蹤時將此資訊傳遞至 Trace 屬性以顯示之。

(繼承來源 Control)
ClearCachedClientID()

將快取的 ClientID 值設定為 null

(繼承來源 Control)
ClearChildControlState()

刪除伺服器控制項之子控制項的控制項狀態資訊。

(繼承來源 Control)
ClearChildState()

刪除所有伺服器控制項之子控制項的檢視狀態和控制項狀態資訊。

(繼承來源 Control)
ClearChildViewState()

刪除所有伺服器控制項之子控制項的檢視狀態資訊。

(繼承來源 Control)
ClearEffectiveClientIDMode()

將目前的控制項執行個體和任何子控制項的 ClientIDMode 屬性設定為 Inherit

(繼承來源 Control)
ConfirmInitState()

設定資料繫結控制項之初始化的狀態。

(繼承來源 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

將不被 Style 物件封裝的屬性從指定的 Web 伺服器控制項複製到呼叫這個方法的 Web 伺服器控制項上。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
CreateAutoGeneratedColumn(AutoGeneratedFieldProperties)
已淘汰.

建立自動產生的資料行欄位。

CreateChildControls()

根據儲存在檢視狀態中的值,建立用來呈現複合資料繫結控制項的控制項階層架構。

(繼承來源 CompositeDataBoundControl)
CreateChildControls(IEnumerable, Boolean)

使用特定資料來源建立用於呈現 GridView 控制項的控制階層架構。

CreateChildTable()

建立新的子資料表。

CreateColumns(PagedDataSource, Boolean)

建立用於建置控制階層架構的資料行欄位集合。

CreateControlCollection()

建立新的 ControlCollection 物件來保存伺服器控制項的子控制項 (常值和伺服器)。

(繼承來源 Control)
CreateControlStyle()

建立控制項的預設樣式。

CreateDataSourceSelectArguments()

建立 DataSourceSelectArguments 物件,其包含傳遞至資料來源用於處理的引數。

CreateRow(Int32, Int32, DataControlRowType, DataControlRowState)

建立 GridView 控制項中的資料列。

DataBind()

將資料來源繫結至 GridView 控制項。 這個方法無法被繼承。

DataBind(Boolean)

使用會引發 DataBinding 事件的選項,繫結資料來源至叫用的伺服器控制項及其所有子控制項。

(繼承來源 Control)
DataBindChildren()

繫結資料來源至伺服器控制項的子控制項。

(繼承來源 Control)
DeleteRow(Int32)

刪除資料來源中指定索引的資料錄。

Dispose()

啟用伺服器控制項,在它從記憶體釋放之前執行最後清除。

(繼承來源 Control)
EndRenderTracing(TextWriter, Object)

結束轉譯資料的設計階段追蹤。

(繼承來源 Control)
EnsureChildControls()

判斷伺服器控制項是否包含子控制項。 如果不包含,則建立子控制項。

(繼承來源 Control)
EnsureDataBound()

如果設定了 DataBind() 屬性且資料繫結控制項標記為需要繫結,則會呼叫 DataSourceID 方法。

(繼承來源 BaseDataBoundControl)
EnsureID()

為尚未指定識別項的控制項,建立識別項。

(繼承來源 Control)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
ExtractRowValues(IOrderedDictionary, GridViewRow, Boolean, Boolean)

擷取在指定資料列內宣告之每個欄位的值,並將它們儲存在指定的 IOrderedDictionary 物件中。

FindControl(String)

在目前命名容器搜尋具有指定 id 參數的伺服器控制項。

(繼承來源 Control)
FindControl(String, Int32)

使用指定的 id 和有助於搜尋之 pathOffset 參數中所指定的整數,在目前的命名容器中搜尋伺服器控制項。 您不應該覆寫這個版本的 FindControl 方法。

(繼承來源 Control)
Focus()

設定控制項的輸入焦點。

(繼承來源 Control)
GetCallbackResult()

傳回以控制項為目標之回呼事件的結果。

GetCallbackScript(IButtonControl, String)

為執行排序作業的按鈕建立回呼指令碼。

GetData()

擷取 DataSourceView 物件,資料繫結控制項會用來執行資料作業。

(繼承來源 DataBoundControl)
GetDataSource()

擷取與資料繫結控制項關聯的 IDataSource 介面 (如果有的話)。

(繼承來源 DataBoundControl)
GetDesignModeState()

取得控制項的設計階段資料。

(繼承來源 Control)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetRouteUrl(Object)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(RouteValueDictionary)

取得會對應於一組路由參數的 URL。

(繼承來源 Control)
GetRouteUrl(String, Object)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetRouteUrl(String, RouteValueDictionary)

取得 URL,此 URL 對應於一組路由參數及一個路由名稱。

(繼承來源 Control)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetUniqueIDRelativeTo(Control)

傳回指定之控制項 UniqueID 屬性的前置部分。

(繼承來源 Control)
HasControls()

判斷伺服器控制項是否包含任何子控制項。

(繼承來源 Control)
HasEvents()

傳回值,指出控制項或任何子控制項的事件是否已註冊。

(繼承來源 Control)
InitializePager(GridViewRow, Int32, PagedDataSource)

初始化啟用分頁功能時顯示的頁面巡覽列。

InitializeRow(GridViewRow, DataControlField[])

初始化 GridView 控制項中的資料列。

IsBindableType(Type)

決定指定的資料類型是否可以繫結至 GridView 控制項中的資料行。

IsLiteralContent()

判斷伺服器控制項是否只儲存常值內容。

(繼承來源 Control)
LoadControlState(Object)

載入需要保存之 GridView 控制項中屬性的狀態,即使 EnableViewState 屬性設為 false

LoadViewState(Object)

載入先前儲存的 GridView 控制項檢視狀態。

MapPathSecure(String)

擷取虛擬絕對路徑或相對路徑所對應至的實體路徑。

(繼承來源 Control)
MarkAsDataBound()

將檢視狀態中的控制項狀態設為已成功繫結至資料。

(繼承來源 DataBoundControl)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MergeStyle(Style)

將指定樣式的任何非空白項目複製到 Web 控制項,但不覆寫控制項的任何現有樣式項目。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
OnBubbleEvent(Object, EventArgs)

決定 Web 伺服器控制項的事件是否要向上傳遞至網頁的使用者介面 (UI) 伺服器控制階層架構。

OnCreatingModelDataSource(CreatingModelDataSourceEventArgs)

引發 CreatingModelDataSource 事件。

(繼承來源 DataBoundControl)
OnDataBinding(EventArgs)

引發 DataBinding 事件。

(繼承來源 Control)
OnDataBound(EventArgs)

引發 DataBound 事件。

(繼承來源 BaseDataBoundControl)
OnDataPropertyChanged()

GridViewDataMemberDataSource 屬性變更後,將 DataSourceID 控制項重新繫結至其資料。

OnDataSourceViewChanged(Object, EventArgs)

引發 DataSourceViewChanged 事件。

OnInit(EventArgs)

引發 Init 事件。

OnLoad(EventArgs)

處理 Load 事件。

(繼承來源 DataBoundControl)
OnPageIndexChanged(EventArgs)

引發 PageIndexChanged 事件。

OnPageIndexChanging(GridViewPageEventArgs)

引發 PageIndexChanging 事件。

OnPagePreLoad(Object, EventArgs)

設定資料繫結控制項在載入控制項之前的初始化狀態。

OnPreRender(EventArgs)

引發 PreRender 事件。

OnRowCancelingEdit(GridViewCancelEditEventArgs)

引發 RowCancelingEdit 事件。

OnRowCommand(GridViewCommandEventArgs)

引發 RowCommand 事件。

OnRowCreated(GridViewRowEventArgs)

引發 RowCreated 事件。

OnRowDataBound(GridViewRowEventArgs)

引發 RowDataBound 事件。

OnRowDeleted(GridViewDeletedEventArgs)

引發 RowDeleted 事件。

OnRowDeleting(GridViewDeleteEventArgs)

引發 RowDeleting 事件。

OnRowEditing(GridViewEditEventArgs)

引發 RowEditing 事件。

OnRowUpdated(GridViewUpdatedEventArgs)

引發 RowUpdated 事件。

OnRowUpdating(GridViewUpdateEventArgs)

引發 RowUpdating 事件。

OnSelectedIndexChanged(EventArgs)

引發 SelectedIndexChanged 事件。

OnSelectedIndexChanging(GridViewSelectEventArgs)

引發 SelectedIndexChanging 事件。

OnSorted(EventArgs)

引發 Sorted 事件。

OnSorting(GridViewSortEventArgs)

引發 Sorting 事件。

OnUnload(EventArgs)

引發 Unload 事件。

(繼承來源 Control)
OpenFile(String)

取得用來讀取檔案的 Stream

(繼承來源 Control)
PerformDataBinding(IEnumerable)

將指定的資料來源繫結至 GridView 控制項。

PerformSelect()

從關聯的資料來源擷取資料。

(繼承來源 DataBoundControl)
PrepareControlHierarchy()

建立控制階層架構。

RaiseBubbleEvent(Object, EventArgs)

指派事件的任何來源和它的資訊至控制項的父控制項。

(繼承來源 Control)
RaiseCallbackEvent(String)

建立 GetCallbackEventReference(Control, String, String, String, Boolean) 方法中回呼處理常式的引數。

RaisePostBackEvent(String)

回傳至伺服器時引發 GridView 控制項的適當事件。

RemovedControl(Control)

Control 物件的 Controls 集合中移除子控制項之後呼叫。

(繼承來源 Control)
Render(HtmlTextWriter)

使用指定的 HtmlTextWriter 物件,向用戶端瀏覽器呈現 Web 伺服器控制項內容。

RenderBeginTag(HtmlTextWriter)

將控制項的 HTML 開頭標記呈現在指定的寫入器中。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
RenderChildren(HtmlTextWriter)

將伺服器控制項子系的內容輸出至提供的 HtmlTextWriter 物件,再由這個物件在用戶端上寫入要轉譯的內容。

(繼承來源 Control)
RenderContents(HtmlTextWriter)

將控制項的內容呈現在指定的寫入器。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
RenderControl(HtmlTextWriter)

將伺服器控制項內容輸出至提供的 HtmlTextWriter 物件,並在啟用追蹤時儲存控制項的追蹤資訊。

(繼承來源 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 物件,輸出伺服器控制項內容至提供的 ControlAdapter 物件。

(繼承來源 Control)
RenderEndTag(HtmlTextWriter)

將控制項的 HTML 結尾標記呈現至指定的寫入器。 這個方法主要由控制項開發人員使用。

(繼承來源 WebControl)
ResolveAdapter()

取得負責呈現指定之控制項的控制項配置器。

(繼承來源 Control)
ResolveClientUrl(String)

取得瀏覽器可使用的 URL。

(繼承來源 Control)
ResolveUrl(String)

將 URL 轉換為要求用戶端可使用的 URL。

(繼承來源 Control)
SaveControlState()

儲存需要保存之 GridView 控制項中屬性的狀態,即使 EnableViewState 屬性設為 false

SaveViewState()

載入先前儲存的 GridView 控制項檢視狀態。

SelectRow(Int32)

選取要在 GridView 控制項中編輯的資料列。

SetDesignModeState(IDictionary)

設定控制項的設計階段資料。

(繼承來源 Control)
SetEditRow(Int32)

使用指定的資料列索引,將 GridView 控制項中的資料列設為編輯模式。

SetPageIndex(Int32)

使用資料列索引,設定 GridView 控制項的頁面索引。

SetRenderMethodDelegate(RenderMethod)

指定事件處理常式委派,以呈現伺服器控制項及其內容至其父控制項。

(繼承來源 Control)
SetTraceData(Object, Object)

使用追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
SetTraceData(Object, Object, Object)

使用追蹤的物體、追蹤資料機碼和追蹤資料值,設定設計階段期間追蹤呈現資料的追蹤資料。

(繼承來源 Control)
Sort(String, SortDirection)

根據指定排序運算式和方向對 GridView 控制項進行排序。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
TrackViewState()

追蹤 GridView 控制項的檢視狀態變更,以便可將其儲存在該控制項的 StateBag 物件中。 這個物件可透過 ViewState 屬性存取。

UpdateRow(Int32, Boolean)

使用資料列的欄位值更新位於指定資料列索引位置的資料錄。

ValidateDataSource(Object)

驗證資料繫結控制項繫結至的物件是該資料繫結控制項所使用的物件。

(繼承來源 DataBoundControl)

事件

CallingDataMethods

正在呼叫資料方法時發生。

(繼承來源 DataBoundControl)
CreatingModelDataSource

正在建立 ModelDataSource 物件時發生。

(繼承來源 DataBoundControl)
DataBinding

發生於伺服器控制項繫結至資料來源時。

(繼承來源 Control)
DataBound

在伺服器控制項繫結至資料來源之後發生。

(繼承來源 BaseDataBoundControl)
Disposed

發生於伺服器控制項從記憶體釋放時,這是在要求 ASP.NET 網頁時,伺服器控制項生命週期的最後階段。

(繼承來源 Control)
Init

發生於初始化伺服器控制項時,是其生命週期中的第一個步驟。

(繼承來源 Control)
Load

發生於載入伺服器控制項至 Page 物件時。

(繼承來源 Control)
PageIndexChanged

按一下其中一個頁面巡覽區按鈕時發生 (但在 GridView 控制項處理分頁作業之後)。

PageIndexChanging

發生於按一下其中一個頁面巡覽區按鈕時,但是在 GridView 控制項處理分頁作業之前。

PreRender

Control 物件載入之後但在呈現之前發生。

(繼承來源 Control)
RowCancelingEdit

按一下處於編輯模式之資料列的 [取消] 按鈕時發生 (但在資料列結束編輯模式之前)。

RowCommand

按一下 GridView 控制項中的按鈕時發生。

RowCreated

建立 GridView 控制項中的資料列時發生。

RowDataBound

資料列繫結至 GridView 控制項中的資料時發生。

RowDeleted

按一下資料列的 [刪除] 按鈕時發生 (但在 GridView 控制項刪除資料列之後)。

RowDeleting

按一下資料列的 [刪除] 按鈕時發生 (但在 GridView 控制項刪除資料列之前)。

RowEditing

按一下資料列的 [編輯] 按鈕時發生 (但在 GridView 控制項進入編輯模式之前)。

RowUpdated

按一下資料列的 [更新] 按鈕時發生 (但在 GridView 控制項更新資料列之後)。

RowUpdating

按一下資料列的 [更新] 按鈕時發生 (但在 GridView 控制項更新資料列之前)。

SelectedIndexChanged

按一下資料列的 [選取] 按鈕時發生 (但在 GridView 控制項處理選取作業之後)。

SelectedIndexChanging

按一下資料列的 [選取] 按鈕時發生 (但在 GridView 控制項處理選取作業之前)。

Sorted

按一下排序資料行的超連結時發生 (但在 GridView 控制項處理排序作業之後)。

Sorting

按一下排序資料行的超連結時發生 (但在 GridView 控制項處理排序作業之前)。

Unload

發生於伺服器控制項從記憶體卸載時。

(繼承來源 Control)

明確介面實作

IAttributeAccessor.GetAttribute(String)

使用指定的名稱,取得 Web 控制項的屬性。

(繼承來源 WebControl)
IAttributeAccessor.SetAttribute(String, String)

將 Web 控制項的屬性設定為指定的名稱和值。

(繼承來源 WebControl)
ICallbackContainer.GetCallbackScript(IButtonControl, String)

為執行排序作業的按鈕建立回呼指令碼。

ICallbackEventHandler.GetCallbackResult()

傳回以控制項為目標之回呼事件的結果。

ICallbackEventHandler.RaiseCallbackEvent(String)

建立 GetCallbackEventReference(Control, String, String, String, Boolean) 方法中回呼處理常式的引數。

IControlBuilderAccessor.ControlBuilder

如需這個成員的說明,請參閱 ControlBuilder

(繼承來源 Control)
IControlDesignerAccessor.GetDesignModeState()

如需這個成員的說明,請參閱 GetDesignModeState()

(繼承來源 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

如需這個成員的說明,請參閱 SetDesignModeState(IDictionary)

(繼承來源 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

如需這個成員的說明,請參閱 SetOwnerControl(Control)

(繼承來源 Control)
IControlDesignerAccessor.UserData

如需這個成員的說明,請參閱 UserData

(繼承來源 Control)
IDataBindingsAccessor.DataBindings

如需這個成員的說明,請參閱 DataBindings

(繼承來源 Control)
IDataBindingsAccessor.HasDataBindings

如需這個成員的說明,請參閱 HasDataBindings

(繼承來源 Control)
IDataBoundControl.DataKeyNames

針對資料繫結控制項中顯示的項目,取得或設定主索引鍵欄位的名稱。

IDataBoundControl.DataMember

取得或設定資料來源控制項公開的資料表,以繫結至資料繫結控制項。

IDataBoundControl.DataSource

取得或設定資料繫結控制項從中擷取其資料項目清單的資料來源物件。

IDataBoundControl.DataSourceID

取得或設定資料來源的識別碼,資料繫結控制項會從其中擷取資料項目清單。

IDataBoundControl.DataSourceObject

取得或設定資料繫結控制項從中擷取其資料項目清單的資料來源物件。

IDataBoundListControl.ClientIDRowSuffix

取得或設定資料欄位的名稱,這些值會附加至 ClientID 屬性,以便識別資料繫結控制項的每一個唯一的執行個體。

IDataBoundListControl.DataKeys

取得物件集合,這些物件表示資料繫結控制項中的 DataKeys 值。

IDataBoundListControl.EnablePersistedSelection

取得或設定值,指出是根據索引還是資料索引鍵值來選取資料列。

IDataBoundListControl.SelectedDataKey

取得物件,其中包含資料繫結控制項中所選取資料列的資料索引鍵值。

IDataBoundListControl.SelectedIndex

取得或設定資料繫結控制項中所選取資料列的索引。

IDataKeysControl.ClientIDRowSuffixDataKeys

取得資料值,這些值會在 ASP.NET 產生 ClientID 值時,用來識別資料繫結控制項的每個唯一的執行個體。

IExpressionsAccessor.Expressions

如需這個成員的說明,請參閱 Expressions

(繼承來源 Control)
IExpressionsAccessor.HasExpressions

如需這個成員的說明,請參閱 HasExpressions

(繼承來源 Control)
IFieldControl.FieldsGenerator

取得或設定控制項,這個控制項會自動產生資料繫結控制項的資料行,以供 ASP.NET 動態資料使用。

IParserAccessor.AddParsedSubObject(Object)

如需這個成員的說明,請參閱 AddParsedSubObject(Object)

(繼承來源 Control)
IPersistedSelector.DataKey

如需這個成員的說明,請參閱 DataKey

IPostBackContainer.GetPostBackOptions(IButtonControl)

建立表示指定按鈕控制項之回傳行為的 PostBackOptions 物件。

IPostBackEventHandler.RaisePostBackEvent(String)

回傳至伺服器時引發 GridView 控制項的適當事件。

擴充方法

EnablePersistedSelection(BaseDataBoundControl)
已淘汰.

啟用要保存於資料控制項中且支援選取和分頁的選項。

FindDataSourceControl(Control)

傳回與指定之控制項的資料控制項相關聯的資料來源。

FindFieldTemplate(Control, String)

傳回在指定之控制項的命名容器中所指定資料行的欄位樣板。

FindMetaTable(Control)

傳回包含資料控制項的中繼資料表物件。

GetDefaultValues(INamingContainer)

取得所指定資料控制項的預設值集合。

GetMetaTable(INamingContainer)

取得所指定資料控制項中的資料表中繼資料。

SetMetaTable(INamingContainer, MetaTable)

設定所指定資料控制項中的資料表中繼資料。

SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>)

設定所指定資料控制項的資料表中繼資料及預設值對應。

SetMetaTable(INamingContainer, MetaTable, Object)

設定所指定資料控制項的資料表中繼資料及預設值對應。

TryGetMetaTable(INamingContainer, MetaTable)

判斷資料表中繼資料是否可供使用。

EnableDynamicData(INamingContainer, Type)

針對指定的資料控制項啟用動態資料行為。

EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>)

針對指定的資料控制項啟用動態資料行為。

EnableDynamicData(INamingContainer, Type, Object)

針對指定的資料控制項啟用動態資料行為。

適用於

另請參閱