GridView 类

定义

在表中显示数据源的值,其中每列表示一个字段,每行表示一条记录。Displays the values of a data source in a table where each column represents a field and each row represents a record. 使用 GridView 控件可以选择和编辑这些项以及对它们进行排序。The GridView control enables you to select, sort, and edit these items.

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.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
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, IDataBoundListControl, IDataKeysControl, IFieldControl, IPersistedSelector, IPostBackContainer, IPostBackEventHandler
继承
属性
实现

示例

本主题提供了包含源代码的 Visual Studio 网站项目:下载A Visual Studio Web site project with source code is available to accompany this topic: Download.

下面的示例演示如何使用 GridView 控件显示 Microsoft SQL Server 中的 AdventureWorksLT 示例数据库的 Customers 表中的值。The following example demonstrates how use the GridView control to display the values from the Customers table of the AdventureWorksLT sample database in Microsoft SQL Server. 使用 SqlDataSource 控件检索值。The values are retrieved using a SqlDataSource control.

<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 控件,以便您可以编辑记录。The following example demonstrates how to use the GridView control and a LinqDataSource control so that you can edit records.

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

有关演示如何访问单元格中的值的示例,请参阅 GridViewRowFor an example demonstrating how to access values in cells, see GridViewRow.

注解

本主题内容:In this topic:

介绍Introduction

GridView 控件用于在表中显示数据源的值。The GridView control is used to display the values of a data source in a table. 每个列表示一个字段,而每行表示一条记录。Each column represents a field, while each row represents a record. GridView 控件支持以下功能:The GridView control supports the following features:

  • 绑定到数据源控件,如 SqlDataSourceBinding to data source controls, such as SqlDataSource.

  • 内置的排序功能。Built-in sort capabilities.

  • 内置的更新和删除功能。Built-in update and delete capabilities.

  • 内置的分页功能。Built-in paging capabilities.

  • 内置行选择功能。Built-in row selection capabilities.

  • 以编程方式访问 GridView 对象模型,以动态设置属性、处理事件等。Programmatic access to the GridView object model to dynamically set properties, handle events, and so on.

  • 多个键字段。Multiple key fields.

  • 超链接列的多个数据字段。Multiple data fields for the hyperlink columns.

  • 通过主题和样式自定义外观。Customizable appearance through themes and styles.

  • 若要了解 ASP.NET 中可用的其他数据绑定控件,请参阅数据绑定 Web 服务器控件To learn about the other data-bound controls that are available in ASP.NET, see Data-Bound Web Server Controls.

备注

如果你熟悉 .NET Framework 版本1.0 中的 DataGrid 控件,GridView 控件是 DataGrid 控件的后继控件。If you are familiar with the DataGrid control from the .NET Framework version 1.0, the GridView control is the successor to the DataGrid control.

列字段Column Fields

GridView 控件中的每一列都由一个 DataControlField 对象表示。Each column in the GridView control is represented by a DataControlField object. 默认情况下,AutoGenerateColumns 属性设置为 true,这将为数据源中的每个字段创建 AutoGeneratedField 对象。By default, the AutoGenerateColumns property is set to true, which creates an AutoGeneratedField object for each field in the data source. 然后,每个字段以每个字段在数据源中出现的顺序呈现为 GridView 控件中的一列。Each field is then rendered as a column in the GridView control in the order that each field appears in the data source.

还可以通过将 AutoGenerateColumns 属性设置为 false,然后定义自己的列字段集合,手动控制在 GridView 控件中显示的列字段。You can also manually control which column fields appear in the GridView control by setting the AutoGenerateColumns property to false and then defining your own column field collection. 不同的列字段类型确定控件中列的行为。Different column field types determine the behavior of the columns in the control. 下表列出了可以使用的不同列字段类型。The following table lists the different column field types that can be used.

列字段类型Column field type 说明Description
BoundField 显示数据源中的字段的值。Displays the value of a field in a data source. 这是 GridView 控件的默认列类型。This is the default column type of the GridView control.
ButtonField 显示 GridView 控件中每个项的命令按钮。Displays a command button for each item in the GridView control. 这使您能够创建自定义按钮控件的列,例如 "添加" 或 "移除" 按钮。This enables you to create a column of custom button controls, such as the Add or the Remove button.
CheckBoxField GridView 控件中的每个项显示一个复选框。Displays a check box for each item in the GridView control. 此列字段类型通常用于显示具有布尔值的字段。This column field type is commonly used to display fields with a Boolean value.
CommandField 显示预定义的命令按钮,以执行选择、编辑或删除操作。Displays predefined command buttons to perform select, edit, or delete operations.
HyperLinkField 将数据源中的字段值显示为超链接。Displays the value of a field in a data source as a hyperlink. 通过此列字段类型,可以将第二个字段绑定到超链接的 URL。This column field type enables you to bind a second field to the hyperlink's URL.
ImageField 显示 GridView 控件中每个项的图像。Displays an image for each item in the GridView control.
TemplateField 根据指定的模板为 GridView 控件中的每个项显示用户定义的内容。Displays user-defined content for each item in the GridView control according to a specified template. 此列字段类型使您能够创建自定义列字段。This column field type enables you to create a custom column field.

若要以声明方式定义列字段集合,请首先在 GridView 控件的开始标记和结束标记之间添加开始和结束 <Columns> 标记。To define a column field collection declaratively, first add opening and closing <Columns> tags between the opening and closing tags of the GridView control. 接下来,列出要在开始和结束 <Columns> 标记之间包括的列字段。Next, list the column fields that you want to include between the opening and closing <Columns> tags. 指定的列按列出顺序添加到 Columns 集合中。The columns specified are added to the Columns collection in the order listed. Columns 集合存储控件中的所有列字段,并使您能够以编程方式管理 GridView 控件中的列字段。The Columns collection stores all the column fields in the control and enables you to programmatically manage the column fields in the GridView control.

显式声明的列字段可与自动生成的列字段一起显示。Explicitly declared column fields can be displayed in combination with automatically generated column fields. 如果同时使用这两个列,则将首先呈现显式声明的列字段,后跟自动生成的列字段。When both are used, explicitly declared column fields are rendered first, followed by the automatically generated column fields.

备注

自动生成的列字段不会添加到 Columns 集合中。Automatically generated column fields are not added to the Columns collection.

绑定到数据Binding to Data

GridView 控件可以绑定到数据源控件(如 SqlDataSource 控件或 ObjectDataSource 控件),也可以绑定到实现 System.Collections.IEnumerable 接口的任何数据源集合,例如 System.Data.DataViewSystem.Collections.ArrayListSystem.Collections.Generic.List<T>或其他集合类型。The GridView control can be bound to a data source control (such as the SqlDataSource control or ObjectDataSource control) or to any data source collection that implements the System.Collections.IEnumerable interface, such as System.Data.DataView, System.Collections.ArrayList, System.Collections.Generic.List<T>, or other collection types. 使用以下方法之一将 GridView 控件绑定到相应的数据源类型:Use one of the following methods to bind the GridView control to the appropriate data source type:

  • 若要绑定到数据源控件,请将 GridView 控件的 DataSourceID 属性设置为数据源控件的 ID 值。To bind to a data source control, set the DataSourceID property of the GridView control to the ID value of the data source control. GridView 控件将自动绑定到指定的数据源控件,并可以利用数据源控件的功能执行排序、更新、删除和分页。The GridView control automatically binds to the specified data source control and can take advantage of the data source control's capabilities to perform sorting, updating, deleting, and paging. 这是绑定到数据的首选方法。This is the preferred method to bind to data.

  • 若要绑定到实现 System.Collections.IEnumerable 接口的数据源,请以编程方式将 GridView 控件的 DataSource 属性设置为数据源,然后调用 DataBind 方法。To bind to a data source that implements the System.Collections.IEnumerable interface, programmatically set the DataSource property of the GridView control to the data source and then call the DataBind method. 使用此方法时,GridView 控件不提供内置排序、更新、删除和分页功能。When using this method, the GridView control does not provide built-in sort, update, delete, and paging functionality. 需要使用相应的事件来提供此功能。You need to provide this functionality by using the appropriate event.

有关数据绑定的详细信息,请参阅ASP.NET 数据访问内容映射For more information about data binding, see ASP.NET Data Access Content Map.

备注

此控件可用于显示用户输入,其中可能包括恶意客户端脚本。This control can be used to display user input, which might include malicious client script. 在应用程序中显示可执行脚本、SQL 语句或其他代码之前,请检查从该客户端发送的任何信息。Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. 在此控件中显示值之前,强烈建议您尽可能对值进行 HTML 编码(默认情况下,BoundField 类对值进行 HTML 编码)。Whenever possible, it is strongly recommended that values are HTML-encoded before they are displayed in this control (the BoundField class HTML-encodes values by default). ASP.NET 提供输入请求验证功能来阻止用户输入中的脚本和 HTML。ASP.NET provides an input request validation feature to block script and HTML in user input. 还提供验证服务器控件以评估用户输入。Validation server controls are also provided to assess user input. 有关详细信息,请参阅验证控件简介For more information, see Introduction to the Validation Controls.

数据操作Data Operations

GridView 控件提供了许多内置功能,使用户可以对控件中的项进行排序、更新、删除、选择和分页。The GridView control provides many built-in capabilities that allow the user to sort, update, delete, select, and page through items in the control. GridView 控件绑定到数据源控件时,GridView 控件可以利用数据源控件的功能,并提供自动排序、更新和删除功能。When the GridView control is bound to a data source control, the GridView control can take advantage of the data source control's capabilities and provide automatic sort, update, and delete functionality.

备注

GridView 控件可以提供对其他类型的数据源的排序、更新和删除的支持。The GridView control can provide support for sorting, updating, and deleting with other types of data sources. 但是,你将需要为这些操作的实现提供相应的事件处理程序。However, you will need to provide an appropriate event handler with the implementation for these operations.

排序允许用户通过单击列的标题,对 GridView 控件中的项进行排序。Sorting allows the user to sort the items in the GridView control with respect to a specific column by clicking on the column's header. 若要启用排序,请将 AllowSorting 属性设置为 trueTo enable sorting, set the AllowSorting property to true.

单击 "编辑"、"删除"、"删除" 和 "选择" 命令名称的 TemplateField ButtonField 按钮时,自动更新、删除和选择功能将启用。The automatic updating, deleting, and selection functionalities are enabled when a button in a ButtonField or TemplateField column field, with a command name of "Edit", "Delete", and "Select", respectively, is clicked. 如果 "AutoGenerateEditButton"、"AutoGenerateDeleteButton" 或 "AutoGenerateSelectButton" 属性分别设置为 trueGridView 控件可以使用 "编辑"、"删除" 或 "选择" 按钮自动添加 CommandField 的列字段。The GridView control can automatically add a CommandField column field with an Edit, Delete, or Select button if the AutoGenerateEditButton, AutoGenerateDeleteButton, or AutoGenerateSelectButton property is set to true, respectively.

备注

GridView 控件不直接支持将记录插入到数据源中。Inserting records into the data source is not directly supported by the GridView control. 但是,可以通过将 GridView 控件与 DetailsViewFormView 控件结合使用来插入记录。However, it is possible to insert records by using the GridView control in conjunction with the DetailsView or FormView control. 有关详细信息,请分别参阅 DetailsViewFormViewFor more information, see DetailsView or FormView, respectively.

GridView 控件可以自动将记录分为多页,而不是同时在数据源中显示所有记录。Instead of displaying all the records in the data source at the same time, the GridView control can automatically break the records up into pages. 若要启用分页,请将 AllowPaging 属性设置为 trueTo enable paging, set the AllowPaging property to true.

备注

GridView 控件基于存储在 ViewState中的信息在回发时重新创建。The GridView control is re-created on postback based on the information that is stored in ViewState. 如果 GridView 控件包括 TemplateFieldCommandFieldCausesValidation 属性设置为 true,则 EnableViewState 属性还必须设置为 true,以确保并发数据操作(如更新和删除)应用于相应的行。If the GridView control includes a TemplateField or a CommandField with the CausesValidation property set to true, then the EnableViewState property must also be set to true to ensure that concurrent data operations, such as updates and deletes, apply to the appropriate row.

自定义用户界面Customizing the User Interface

您可以通过设置控件的不同部分的样式属性来自定义 GridView 控件的外观。You can customize the appearance of the GridView control by setting the style properties for the different parts of the control. 下表列出了不同的样式属性。The following table lists the different style properties.

Style 属性Style property 说明Description
AlternatingRowStyle GridView 控件中的交替数据行的样式设置。The style settings for the alternating data rows in the GridView control. 设置此属性时,数据行将在 RowStyle 设置和 AlternatingRowStyle 设置之间交替显示。When this property is set, the data rows are displayed alternating between the RowStyle settings and the AlternatingRowStyle settings.
EditRowStyle GridView 控件中正在编辑的行的样式设置。The style settings for the row being edited in the GridView control.
EmptyDataRowStyle 当数据源不包含任何记录时,GridView 控件中显示的空数据行的样式设置。The style settings for the empty data row displayed in the GridView control when the data source does not contain any records.
FooterStyle GridView 控件的脚注行的样式设置。The style settings for the footer row of the GridView control.
HeaderStyle GridView 控件的标题行的样式设置。The style settings for the header row of the GridView control.
PagerStyle GridView 控件的页导航行的样式设置。The style settings for the pager row of the GridView control.
RowStyle GridView 控件中的数据行的样式设置。The style settings for the data rows in the GridView control. 如果同时设置了 AlternatingRowStyle 属性,则会在 RowStyle 设置与 AlternatingRowStyle 设置之间交替显示数据行。When the AlternatingRowStyle property is also set, the data rows are displayed alternating between the RowStyle settings and the AlternatingRowStyle settings.
SelectedRowStyle GridView 控件中的所选行的样式设置。The style settings for the selected row in the GridView control.
SortedAscendingCellStyle GridView 控件中对数据进行排序的数据列的样式设置。The style setting for the data column the data is sorted by in the GridView control. 设置此样式后,当数据按升序排序时,样式(例如突出显示的列)将应用于单元格。When this style is set, the style (for example, highlighted column) is applied to cells when the data is sorted in ascending order.
SortedAscendingHeaderStyle GridView 控件中对数据进行排序的数据列的样式设置。The style setting for the data column the data is sorted by in the GridView control. 如果设置此样式,则在按升序对数据进行排序时,将在 GridView 控件的标头上放置一个指示数据按升序排序的箭头。When this style is set, an arrow indicating the data is sorted ascending is placed on the header of the GridView control when the data is sorted in ascending order.
SortedDescendingCellStyle GridView 控件中对数据进行排序的数据列的样式设置。The style setting for the data column the data is sorted by in the GridView control. 如果设置此样式,则在按降序对数据进行排序时,样式(例如突出显示的列)将应用于单元。When this style is set, the style (for example, highlighted column) is applied to cells when the data is sorted in descending order.
SortedDescendingHeaderStyle GridView 控件中对数据进行排序的数据列的样式设置。The style setting for the data column the data is sorted by in the GridView control. 如果设置此样式,则在按降序对数据进行排序时,将向下箭头置于 GridView 的标头。When this style is set, an arrow pointing down is placed on the header of the GridView when the data is sorted in descending order.

还可以显示或隐藏控件的不同部分。You can also show or hide different parts of the control. 下表列出了属性,这些属性控制要显示或隐藏的部分。The following table lists the properties that control which parts are shown or hidden.

propertiesProperty 说明Description
ShowFooter 显示或隐藏 GridView 控件的页脚部分。Shows or hides the footer section of the GridView control.
ShowHeader 显示或隐藏 GridView 控件的标头部分。Shows or hides the header section of the GridView control.

事件Events

GridView 控件提供了多个可对其进行编程的事件。The GridView control provides several events that you can program against. 这使您可以在每次发生事件时运行自定义例程。This enables you to run a custom routine whenever an event occurs. 下表列出了 GridView 控件支持的事件。The following table lists the events that are supported by the GridView control.

事件Event 说明Description
PageIndexChanged 在单击某一页导航按钮时,但在 GridView 控件处理分页操作之后发生。Occurs when one of the pager buttons is clicked, but after the GridView control handles the paging operation. 当用户导航到控件中的其他页面后,如果需要执行某个任务,通常会使用此事件。This event is commonly used when you need to perform a task after the user navigates to a different page in the control.
PageIndexChanging 在单击某一页导航按钮时,但在 GridView 控件处理分页操作之前发生。Occurs when one of the pager buttons is clicked, but before the GridView control handles the paging operation. 此事件通常用于取消分页操作。This event is often used to cancel the paging operation.
RowCancelingEdit 在单击某一行的 "取消" 按钮时,但在 GridView 控件退出编辑模式之前发生。Occurs when a row's Cancel button is clicked, but before the GridView control exits edit mode. 此事件通常用于停止取消操作。This event is often used to stop the canceling operation.
RowCommand GridView 控件中单击某个按钮时发生。Occurs when a button is clicked in the GridView control. 此事件通常用于在控件中单击按钮时执行任务。This event is often used to perform a task when a button is clicked in the control.
RowCreated GridView 控件中创建新行时发生。Occurs when a new row is created in the GridView control. 此事件通常用于在创建行时修改行的内容。This event is often used to modify the contents of a row when the row is created.
RowDataBound 当数据行绑定到 GridView 控件中的数据时发生。Occurs when a data row is bound to data in the GridView control. 当行绑定到数据时,此事件通常用于修改行的内容。This event is often used to modify the contents of a row when the row is bound to data.
RowDeleted 在单击某一行的 "删除" 按钮时,但在 GridView 控件从数据源中删除该记录后发生。Occurs when a row's Delete button is clicked, but after the GridView control deletes the record from the data source. 此事件通常用于检查删除操作的结果。This event is often used to check the results of the delete operation.
RowDeleting 在单击某一行的 "删除" 按钮时,但在 GridView 控件从数据源中删除该记录之前发生。Occurs when a row's Delete button is clicked, but before the GridView control deletes the record from the data source. 此事件通常用于取消删除操作。This event is often used to cancel the deleting operation.
RowEditing 发生在单击某一行的“编辑”按钮以后,GridView 控件进入编辑模式之前。Occurs when a row's Edit button is clicked, but before the GridView control enters edit mode. 此事件通常用于取消编辑操作。This event is often used to cancel the editing operation.
RowUpdated 发生在单击某一行的“更新”按钮,并且 GridView 控件对该行进行更新之后。Occurs when a row's Update button is clicked, but after the GridView control updates the row. 此事件通常用于检查更新操作的结果。This event is often used to check the results of the update operation.
RowUpdating 发生在单击某一行的“更新”按钮以后,GridView 控件对该行进行更新之前。Occurs when a row's Update button is clicked, but before the GridView control updates the row. 此事件通常用于取消更新操作。This event is often used to cancel the updating operation.
SelectedIndexChanged 发生在单击某一行的“选择”按钮,GridView 控件对相应的选择操作进行处理之后。Occurs when a row's Select button is clicked, but after the GridView control handles the select operation. 此事件通常用于在控件中选择行后执行任务。This event is often used to perform a task after a row is selected in the control.
SelectedIndexChanging 发生在单击某一行的“选择”按钮以后,GridView 控件对相应的选择操作进行处理之前。Occurs when a row's Select button is clicked, but before the GridView control handles the select operation. 此事件通常用于取消选择操作。This event is often used to cancel the selection operation.
Sorted 在单击用于列排序的超链接时,但在 GridView 控件对相应的排序操作进行处理之后发生。Occurs when the hyperlink to sort a column is clicked, but after the GridView control handles the sort operation. 此事件通常用于在用户单击用于对列进行排序的超链接后执行任务。This event is commonly used to perform a task after the user clicks a hyperlink to sort a column.
Sorting 在单击用于列排序的超链接时,但在 GridView 控件对相应的排序操作进行处理之前发生。Occurs when the hyperlink to sort a column is clicked, but before the GridView control handles the sort operation. 此事件通常用于取消排序操作或执行自定义的排序例程。This event is often used to cancel the sorting operation or to perform a custom sorting routine.

可访问性Accessibility

有关如何配置此控件以生成符合辅助功能标准的标记的信息,请参阅Visual Studio 中的辅助功能和 ASP.NETASP.NET 控件和辅助功能For information about how to configure this control so that it generates markup that conforms to accessibility standards, see Accessibility in Visual Studio and ASP.NET and ASP.NET Controls and Accessibility.

声明性语法Declarative Syntax

<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 类的新实例。Initializes a new instance of the GridView class.

属性

AccessKey

获取或设置使您得以快速导航到 Web 服务器控件的访问键。Gets or sets the access key that allows you to quickly navigate to the Web server control.

(继承自 WebControl)
Adapter

获取控件的浏览器特定适配器。Gets the browser-specific adapter for the control.

(继承自 Control)
AllowCustomPaging

获取或设置指示是否启用自定义分页的值。Gets or sets a value that indicates whether custom paging is enabled.

AllowPaging

获取或设置一个值,该值指示是否启用分页功能。Gets or sets a value indicating whether the paging feature is enabled.

AllowSorting

获取或设置一个值,该值指示是否启用排序功能。Gets or sets a value indicating whether the sorting feature is enabled.

AlternatingRowStyle

获取对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中的交替数据行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of alternating data rows in a GridView control.

AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。Gets or sets the application-relative virtual directory of the Page or UserControl object that contains this control.

(继承自 Control)
Attributes

获取与控件的特性不对应的任意特性(只用于呈现)的集合。Gets the collection of arbitrary attributes (for rendering only) that do not correspond to properties on the control.

(继承自 WebControl)
AutoGenerateColumns

获取或设置一个值,该值指示是否为数据源中的每个字段自动创建绑定字段。Gets or sets a value indicating whether bound fields are automatically created for each field in the data source.

AutoGenerateDeleteButton

获取或设置一个值,该值指示每个数据行都带有“删除”按钮的 CommandField 字段列是否自动添加到 GridView 控件。Gets or sets a value indicating whether a CommandField field column with a Delete button for each data row is automatically added to a GridView control.

AutoGenerateEditButton

获取或设置一个值,该值指示每个数据行都带有“编辑”按钮的 CommandField 字段列是否自动添加到 GridView 控件。Gets or sets a value indicating whether a CommandField field column with an Edit button for each data row is automatically added to a GridView control.

AutoGenerateSelectButton

获取或设置一个值,该值指示每个数据行都带有“选择”按钮的 CommandField 字段列是否自动添加到 GridView 控件。Gets or sets a value indicating whether a CommandField field column with a Select button for each data row is automatically added to a GridView control.

BackColor

获取或设置 Web 服务器控件的背景色。Gets or sets the background color of the Web server control.

(继承自 WebControl)
BackImageUrl

获取或设置要在 GridView 控件的背景中显示的图像的 URL。Gets or sets the URL to an image to display in the background of a GridView control.

BindingContainer

获取包含该控件的数据绑定的控件。Gets the control that contains this control's data binding.

(继承自 Control)
BorderColor

获取或设置 Web 控件的边框颜色。Gets or sets the border color of the Web control.

(继承自 WebControl)
BorderStyle

获取或设置 Web 服务器控件的边框样式。Gets or sets the border style of the Web server control.

(继承自 WebControl)
BorderWidth

获取或设置 Web 服务器控件的边框宽度。Gets or sets the border width of the Web server control.

(继承自 WebControl)
BottomPagerRow

获取一个 GridViewRow 对象,该对象表示 GridView 控件中的底部页导航行。Gets a GridViewRow object that represents the bottom pager row in a GridView control.

Caption

获取或设置要在 GridView 控件的 HTML 标题元素中呈现的文本。Gets or sets the text to render in an HTML caption element in a GridView control. 提供此属性的目的是使辅助技术设备的用户更易于访问控件。This property is provided to make the control more accessible to users of assistive technology devices.

CaptionAlign

获取或设置 GridView 控件中的 HTML 标题元素的水平或垂直位置。Gets or sets the horizontal or vertical position of the HTML caption element in a GridView control. 提供此属性的目的是使辅助技术设备的用户更易于访问控件。This property is provided to make the control more accessible to users of assistive technology devices.

CellPadding

获取或设置单元格的内容和单元格的边框之间的空间量。Gets or sets the amount of space between the contents of a cell and the cell's border.

CellSpacing

获取或设置单元格间的空间量。Gets or sets the amount of space between cells.

ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。Gets a value that indicates whether the server control's child controls have been created.

(继承自 Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。Gets the control ID for HTML markup that is generated by ASP.NET.

(继承自 Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。Gets or sets the algorithm that is used to generate the value of the ClientID property.

(继承自 Control)
ClientIDRowSuffix

获取或设置数据字段的名称,这些数据字段的值附加到 ClientID 属性值,以便唯一标识数据绑定控件的每个实例。Gets or sets the names of the data fields whose values are appended to the ClientID property value to uniquely identify each instance of a data-bound control.

ClientIDRowSuffixDataKeys

获取数据值,在 ASP.NET 生成 ClientID 值时,这些数据值用于唯一标识数据绑定控件的每个实例。Gets the data values that are used to uniquely identify each instance of a data-bound control when ASP.NET generates the ClientID value.

ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。Gets a character value representing the separator character used in the ClientID property.

(继承自 Control)
Columns

获取表示 DataControlField 控件中列字段的 GridView 对象的集合。Gets a collection of DataControlField objects that represent the column fields in a GridView control.

ColumnsGenerator

获取或设置一个控件,该控件将自动为使用 ASP.NET 动态数据功能的 GridView 控件生成列。Gets or sets the control that will automatically generate the columns for a GridView control that uses ASP.NET Dynamic Data features.

Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。Gets the HttpContext object associated with the server control for the current Web request.

(继承自 Control)
Controls

获取复合数据绑定控件内的子控件的集合。Gets a collection of the child controls within the composite data-bound control.

(继承自 CompositeDataBoundControl)
ControlStyle

获取 Web 服务器控件的样式。Gets the style of the Web server control. 此属性主要由控件开发人员使用。This property is used primarily by control developers.

(继承自 WebControl)
ControlStyleCreated

获取一个值,该值指示是否已为 Style 属性创建了 ControlStyle 对象。Gets a value indicating whether a Style object has been created for the ControlStyle property. 此属性主要由控件开发人员使用。This property is primarily used by control developers.

(继承自 WebControl)
CssClass

获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。Gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client.

(继承自 WebControl)
DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。Gets a reference to the naming container if the naming container implements IDataItemContainer.

(继承自 Control)
DataKeyNames

获取或设置一个数组,该数组包含了显示在 GridView 控件中的项的主键字段的名称。Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control.

DataKeys

获取一个 DataKey 对象集合,这些对象表示 GridView 控件中的每一行的数据键值。Gets a collection of DataKey objects that represent the data key value of each row in a GridView control.

DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。Gets a reference to the naming container if the naming container implements IDataKeysControl.

(继承自 Control)
DataMember

当数据源包含多个不同的数据项列表时,获取或设置数据绑定控件绑定到的数据列表的名称。Gets or sets the name of the list of data that the data-bound control binds to, in cases where the data source contains more than one distinct list of data items.

(继承自 DataBoundControl)
DataSource

获取或设置对象,数据绑定控件从该对象中检索其数据项列表。Gets or sets the object from which the data-bound control retrieves its list of data items.

(继承自 BaseDataBoundControl)
DataSourceID

获取或设置控件的 ID,数据绑定控件从该控件中检索其数据项列表。Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.

(继承自 DataBoundControl)
DataSourceObject

获取一个对象,该对象实现 IDataSource 接口,以便提供对该对象的数据内容的访问。Gets an object that implements the IDataSource interface, which provides access to the object's data content.

(继承自 DataBoundControl)
DeleteMethod

获取或设置为了删除数据要调用的方法的名称。Gets or sets the name of the method to call in order to delete data.

DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。Gets a value indicating whether a control is being used on a design surface.

(继承自 Control)
EditIndex

获取或设置要编辑的行的索引。Gets or sets the index of the row to edit.

EditRowStyle

获取对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中为进行编辑而选中的行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the row selected for editing in a GridView control.

EmptyDataRowStyle

获取对 TableItemStyle 对象的引用,使用该对象可以设置当 GridView 控件绑定到不包含任何记录的数据源时会呈现的空数据行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the empty data row rendered when a GridView control is bound to a data source that does not contain any records.

EmptyDataTemplate

获取或设置在 GridView 控件绑定到不包含任何记录的数据源时所呈现的空数据行的用户定义内容。Gets or sets the user-defined content for the empty data row rendered when a GridView control is bound to a data source that does not contain any records.

EmptyDataText

获取或设置在 GridView 控件绑定到不包含任何记录的数据源时所呈现的空数据行中显示的文本。Gets or sets the text to display in the empty data row rendered when a GridView control is bound to a data source that does not contain any records.

Enabled

获取或设置一个值,该值指示是否启用 Web 服务器控件。Gets or sets a value indicating whether the Web server control is enabled.

(继承自 WebControl)
EnableModelValidation

获取或设置一个值,该值指示验证程序控件是否会处理在插入或更新操作过程中出现的异常。Gets or sets a value that indicates whether a validator control will handle exceptions that occur during insert or update operations.

EnablePersistedSelection

获取或设置一个值,该值指示行的选择是基于索引还是数据键值。Gets or sets a value that indicates whether the selection of a row is based on index or on data-key values.

EnableSortingAndPagingCallbacks

获取或设置一个值,该值指示客户端回调是否用于排序和分页操作。Gets or sets a value indicating whether client-side callbacks are used for sorting and paging operations.

EnableTheming

获取或设置一个值,该值指示主题是否应用于该控件。Gets or sets a value indicating whether themes apply to this control.

(继承自 WebControl)
EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.

(继承自 Control)
Events

获取控件的事件处理程序委托列表。Gets a list of event handler delegates for the control. 此属性为只读。This property is read-only.

(继承自 Control)
Font

获取与 Web 服务器控件关联的字体属性。Gets the font properties associated with the Web server control.

(继承自 WebControl)
FooterRow

获取表示 GridViewRow 控件中的脚注行的 GridView 对象。Gets a GridViewRow object that represents the footer row in a GridView control.

FooterStyle

获取一个对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中脚注行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the footer row in a GridView control.

ForeColor

获取或设置 Web 服务器控件的前景色(通常是文本颜色)。Gets or sets the foreground color (typically the color of the text) of the Web server control.

(继承自 WebControl)
GridLines

获取或设置 GridView 控件的网格线样式。Gets or sets the gridline style for a GridView control.

HasAttributes

获取一个值,该值指示控件是否具有特性集。Gets a value indicating whether the control has attributes set.

(继承自 WebControl)
HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。Gets a value indicating whether the current server control's child controls have any saved view-state settings.

(继承自 Control)
HeaderRow

获取表示 GridViewRow 控件中的标题行的 GridView 对象。Gets a GridViewRow object that represents the header row in a GridView control.

HeaderStyle

获取一个对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中的标题行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the header row in a GridView control.

Height

获取或设置 Web 服务器控件的高度。Gets or sets the height of the Web server control.

(继承自 WebControl)
HorizontalAlign

获取或设置 GridView 控件在页面上的水平对齐方式。Gets or sets the horizontal alignment of a GridView control on the page.

ID

获取或设置分配给服务器控件的编程标识符。Gets or sets the programmatic identifier assigned to the server control.

(继承自 Control)
IdSeparator

获取用于分隔控件标识符的字符。Gets the character used to separate control identifiers.

(继承自 Control)
Initialized

获取一个值,该值指示数据绑定控件是否已经初始化。Gets a value indicating whether the data-bound control has been initialized.

(继承自 BaseDataBoundControl)
InsertMethod

获取或设置为了插入数据要调用的方法的名称。Gets or sets the name of the method to call in order to insert data.

(继承自 CompositeDataBoundControl)
IsBoundUsingDataSourceID

获取指示是否设置 DataSourceID 属性的值。Gets a value indicating whether the DataSourceID property is set.

(继承自 BaseDataBoundControl)
IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。Gets a value indicating whether controls contained within this control have control state.

(继承自 Control)
IsDataBindingAutomatic

获取一个值,该值指示数据绑定是否自动进行。Gets a value that indicates whether data binding is automatic.

(继承自 BaseDataBoundControl)
IsEnabled

获取一个值,该值指示是否启用控件。Gets a value indicating whether the control is enabled.

(继承自 WebControl)
IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。Gets a value that indicates whether the server control is saving changes to its view state.

(继承自 Control)
IsUsingModelBinders

获取一个值,该值指示是否使用模型绑定。Gets a value that indicates whether model binding is in use.

(继承自 CompositeDataBoundControl)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。Gets a value indicating whether view state is enabled for this control.

(继承自 Control)
ItemType

获取或设置强类型化数据绑定的数据项目类型的名称。Gets or sets the name of the data item type for strongly typed data binding.

(继承自 DataBoundControl)
LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。Gets a value indicating whether the control participates in loading its view state by ID instead of index.

(继承自 Control)
NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。Gets a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same ID property value.

(继承自 Control)
Page

获取对包含服务器控件的 Page 实例的引用。Gets a reference to the Page instance that contains the server control.

(继承自 Control)
PageCount

获取在 GridView 控件中显示数据源记录所需的页数。Gets the number of pages required to display the records of the data source in a GridView control.

PageIndex

获取或设置当前显示页的索引。Gets or sets the index of the currently displayed page.

PagerSettings

获取对 PagerSettings 对象的引用,使用该对象可以设置 GridView 控件中的页导航按钮的属性。Gets a reference to the PagerSettings object that enables you to set the properties of the pager buttons in a GridView control.

PagerStyle

获取对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中的页导航行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the pager row in a GridView control.

PagerTemplate

获取或设置 GridView 控件中页导航行的自定义内容。Gets or sets the custom content for the pager row in a GridView control.

PageSize

获取或设置 GridView 控件在每页上所显示的记录的数目。Gets or sets the number of records to display on a page in a GridView control.

Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。Gets a reference to the server control's parent control in the page control hierarchy.

(继承自 Control)
RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.

(继承自 Control)
RequiresDataBinding

获取或设置一个值,该值指示是否应调用 DataBind() 方法。Gets or sets a value indicating whether the DataBind() method should be called.

(继承自 BaseDataBoundControl)
RowHeaderColumn

获取或设置用作 GridView 控件的列标题的列的名称。Gets or sets the name of the column to use as the column header for the GridView control. 提供此属性的目的是使辅助技术设备的用户更易于访问控件。This property is provided to make the control more accessible to users of assistive technology devices.

Rows

获取表示 GridViewRow 控件中数据行的 GridView 对象的集合。Gets a collection of GridViewRow objects that represent the data rows in a GridView control.

RowStyle

获取对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中的数据行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the data rows in a GridView control.

SelectArguments

获取数据绑定控件从数据源控件检索数据时使用的 DataSourceSelectArguments 对象。Gets a DataSourceSelectArguments object that the data-bound control uses when retrieving data from a data source control.

(继承自 DataBoundControl)
SelectedDataKey

获取 DataKey 对象,该对象包含 GridView 控件中选中行的数据键值。Gets the DataKey object that contains the data key value for the selected row in a GridView control.

SelectedIndex

获取或设置 GridView 控件中的选中行的索引。Gets or sets the index of the selected row in a GridView control.

SelectedPersistedDataKey

获取或设置 GridView 控件中选择的持久项的数据键值。Gets or sets the data-key value for the persisted selected item in a GridView control.

SelectedRow

获取对 GridViewRow 对象的引用,该对象表示控件中的选中行。Gets a reference to a GridViewRow object that represents the selected row in the control.

SelectedRowStyle

获取对 TableItemStyle 对象的引用,使用该对象可以设置 GridView 控件中的选中行的外观。Gets a reference to the TableItemStyle object that enables you to set the appearance of the selected row in a GridView control.

SelectedValue

获取 GridView 控件中选中行的数据键值。Gets the data key value of the selected row in a GridView control.

SelectMethod

为了读取数据要调用的方法的名称。The name of the method to call in order to read data.

(继承自 DataBoundControl)
ShowFooter

获取或设置一个值,该值指示是否在 GridView 控件中显示脚注行。Gets or sets a value indicating whether the footer row is displayed in a GridView control.

ShowHeader

获取或设置一个值,该值指示是否在 GridView 控件中显示标题行。Gets or sets a value indicating whether the header row is displayed in a GridView control.

ShowHeaderWhenEmpty

获取或设置一个值,该值指示当列没有数据时 GridView 控件中列的标题是否可见。Gets or sets a value that indicates whether the heading of a column in the GridView control is visible when the column has no data.

Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。Gets information about the container that hosts the current control when rendered on a design surface.

(继承自 Control)
SkinID

获取或设置要应用于控件的外观。Gets or sets the skin to apply to the control.

(继承自 WebControl)
SortDirection

获取正在排序的列的排序方向。Gets the sort direction of the column being sorted.

SortedAscendingCellStyle

获取或设置按升序对列排序时 GridView 列的 CSS 样式。Gets or sets the CSS style for a GridView column when the column is sorted in ascending order.

SortedAscendingHeaderStyle

获取或设置按升序对列进行排序时要应用于 GridView 列标题的 CSS 样式。Gets or sets the CSS style to apply to a GridView column heading when the column is sorted in ascending order.

SortedDescendingCellStyle

获取或设置按升序对列进行排序时 GridView 列的样式。Gets or sets the style of a GridView column when the column is sorted in descending order.

SortedDescendingHeaderStyle

获取或设置按降序对列进行排序时要应用于 GridView 列标题的样式。Gets or sets the style to apply to a GridView column heading when the column is sorted in descending order.

SortExpression

获取与正在排序的列关联的排序表达式。Gets the sort expression associated with the column or columns being sorted.

Style

获取将在 Web 服务器控件的外部标记上呈现为样式特性的文本特性的集合。Gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control.

(继承自 WebControl)
SupportsDisabledAttribute

获取一个值,该值指示在控件的 disabled 属性为 IsEnabled 时,控件是否应将呈现的 HTML 元素的 false 特性设置为 "disabled"。Gets a value that indicates whether the control should set the disabled attribute of the rendered HTML element to "disabled" when the control's IsEnabled property is false.

(继承自 BaseDataBoundControl)
TabIndex

获取或设置 Web 服务器控件的选项卡索引。Gets or sets the tab index of the Web server control.

(继承自 WebControl)
TagKey

获取 HtmlTextWriterTag 控件的 GridView 值。Gets the HtmlTextWriterTag value for the GridView control.

TagName

获取控件标记的名称。Gets the name of the control tag. 此属性主要由控件开发人员使用。This property is used primarily by control developers.

(继承自 WebControl)
TemplateControl

获取或设置对包含该控件的模板的引用。Gets or sets a reference to the template that contains this control.

(继承自 Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。Gets the virtual directory of the Page or UserControl that contains the current server control.

(继承自 Control)
ToolTip

获取或设置当鼠标指针悬停在 Web 服务器控件上时显示的文本。Gets or sets the text displayed when the mouse pointer hovers over the Web server control.

(继承自 WebControl)
TopPagerRow

获取一个 GridViewRow 对象,该对象表示 GridView 控件中的顶部页导航行。Gets a GridViewRow object that represents the top pager row in a GridView control.

UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。Gets the unique, hierarchically qualified identifier for the server control.

(继承自 Control)
UpdateMethod

获取或设置为了更新数据要调用的方法的名称。Gets or sets the name of the method to call in order to update data.

UseAccessibleHeader

获取或设置一个值,该值指示 GridView 控件是否以易于访问的格式呈现其标题。Gets or sets a value indicating whether a GridView control renders its header in an accessible format. 提供此属性的目的是使辅助技术设备的用户更易于访问控件。This property is provided to make the control more accessible to users of assistive technology devices.

ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。Gets or sets a value that indicates whether the control checks client input from the browser for potentially dangerous values.

(继承自 Control)
ViewState

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

(继承自 Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。Gets a value that indicates whether the StateBag object is case-insensitive.

(继承自 Control)
ViewStateMode

获取或设置此控件的视图状态模式。Gets or sets the view-state mode of this control.

(继承自 Control)
VirtualItemCount

在使用自定义分页时,获取或设置数据源中的实际项数 GridView 控件绑定。Gets or sets the virtual number of items in the data source that the GridView control is bound to when custom paging is used.

Visible

获取或设置一个值,该值指示服务器控件是否作为 UI 呈现在页上。Gets or sets a value that indicates whether a server control is rendered as UI on the page.

(继承自 Control)
Width

获取或设置 Web 服务器控件的宽度。Gets or sets the width of the Web server control.

(继承自 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

将需要呈现的 HTML 特性和样式添加到指定的 HtmlTextWriterTag 中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriterTag. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
AddedControl(Control, Int32)

在子控件添加到 Controls 对象的 Control 集合后调用。Called after a child control is added to the Controls collection of the Control object.

(继承自 Control)
AddParsedSubObject(Object)

通知服务器控件,分析了一个元素(XML 或 HTML),并将该元素添加到服务器控件的 ControlCollection 对象中。Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object.

(继承自 Control)
ApplyStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,覆盖控件的所有现有的样式元素。Copies any nonblank elements of the specified style to the Web control, overwriting any existing style elements of the control. 此方法主要由控件开发人员使用。This method is primarily used by control developers.

(继承自 WebControl)
ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。Applies the style properties defined in the page style sheet to the control.

(继承自 Control)
BeginRenderTracing(TextWriter, Object)

开始输出数据的设计时追踪。Begins design-time tracing of rendering data.

(继承自 Control)
BuildProfileTree(String, Boolean)

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page.

(继承自 Control)
ClearCachedClientID()

将缓存的 ClientID 值设置为 nullSets the cached ClientID value to null.

(继承自 Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。Deletes the control-state information for the server control's child controls.

(继承自 Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。Deletes the view-state and control-state information for all the server control's child controls.

(继承自 Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。Deletes the view-state information for all the server control's child controls.

(继承自 Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 InheritSets the ClientIDMode property of the current control instance and of any child controls to Inherit.

(继承自 Control)
ConfirmInitState()

设置数据绑定控件的初始化状态。Sets the initialized state of the data-bound control.

(继承自 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

Style 对象未封装的属性从指定的 Web 服务器控件复制到从中调用此方法的 Web 服务器控件。Copies the properties not encapsulated by the Style object from the specified Web server control to the Web server control that this method is called from. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
CreateAutoGeneratedColumn(AutoGeneratedFieldProperties)

创建一个自动生成的列字段。Creates an automatically generated column field.

CreateChildControls()

基于存储在视图状态中的值创建用来呈现复合数据绑定控件的控件层次结构。Creates the control hierarchy that is used to render a composite data-bound control based on the values that are stored in view state.

(继承自 CompositeDataBoundControl)
CreateChildControls(IEnumerable, Boolean)

使用指定数据源创建用于呈现 GridView 控件的控件层次结构。Creates the control hierarchy used to render the GridView control using the specified data source.

CreateChildTable()

创建一个新的子表。Creates a new child table.

CreateColumns(PagedDataSource, Boolean)

创建用来构建控件层次结构的列字段集。Creates the set of column fields used to build the control hierarchy.

CreateControlCollection()

创建一个新 ControlCollection 对象来保存服务器控件的子控件(包括文本控件和服务器控件)。Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control.

(继承自 Control)
CreateControlStyle()

为控件创建默认样式。Creates the default style for the control.

CreateDataSourceSelectArguments()

创建 DataSourceSelectArguments 对象,该对象包含传递到数据源进行处理的参数。Creates the DataSourceSelectArguments object that contains the arguments that get passed to the data source for processing.

CreateRow(Int32, Int32, DataControlRowType, DataControlRowState)

GridView 控件中创建行。Creates a row in the GridView control.

DataBind()

将数据源绑定到 GridView 控件。Binds the data source to the GridView control. 无法继承此方法。This method cannot be inherited.

DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event.

(继承自 Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。Binds a data source to the server control's child controls.

(继承自 Control)
DeleteRow(Int32)

从数据源中删除位于指定索引位置的记录。Deletes the record at the specified index from the data source.

Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。Enables a server control to perform final clean up before it is released from memory.

(继承自 Control)
EndRenderTracing(TextWriter, Object)

结束输出数据的设计时追踪。Ends design-time tracing of rendering data.

(继承自 Control)
EnsureChildControls()

确定服务器控件是否包含子控件。Determines whether the server control contains child controls. 如果不包含,则创建子控件。If it does not, it creates child controls.

(继承自 Control)
EnsureDataBound()

如果设置了 DataBind() 属性且数据绑定控件标记为需要绑定,则调用 DataSourceID 方法。Calls the DataBind() method if the DataSourceID property is set and the data-bound control is marked to require binding.

(继承自 BaseDataBoundControl)
EnsureID()

为尚未分配标识符的控件创建标识符。Creates an identifier for controls that do not have an identifier assigned.

(继承自 Control)
Equals(Object)

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

(继承自 Object)
ExtractRowValues(IOrderedDictionary, GridViewRow, Boolean, Boolean)

检索在指定行中声明的每个字段的值,并将它们存储在指定的 IOrderedDictionary 对象中。Retrieves the values of each field declared within the specified row and stores them in the specified IOrderedDictionary object.

FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。Searches the current naming container for a server control with the specified id parameter.

(继承自 Control)
FindControl(String, Int32)

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. 不应重写此版本的 FindControl 方法。You should not override this version of the FindControl method.

(继承自 Control)
Focus()

为控件设置输入焦点。Sets input focus to a control.

(继承自 Control)
GetCallbackResult()

返回以控件为目标的回调事件的结果。Returns the result of a callback event that targets a control.

GetCallbackScript(IButtonControl, String)

为执行排序操作的按钮创建回调脚本。Creates the callback script for a button that performs a sorting operation.

GetData()

检索数据绑定控件用于执行数据操作的 DataSourceView 对象。Retrieves a DataSourceView object that the data-bound control uses to perform data operations.

(继承自 DataBoundControl)
GetDataSource()

检索与数据绑定控件关联的 IDataSource 接口(如果有)。Retrieves the IDataSource interface that the data-bound control is associated with, if any.

(继承自 DataBoundControl)
GetDesignModeState()

获取控件的设计时数据。Gets design-time data for a control.

(继承自 Control)
GetHashCode()

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

(继承自 Object)
GetRouteUrl(Object)

获取与一组路由参数对应的 URL。Gets the URL that corresponds to a set of route parameters.

(继承自 Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。Gets the URL that corresponds to a set of route parameters.

(继承自 Control)
GetRouteUrl(String, Object)

获取与一组路由参数以及某个路由名称对应的 URL。Gets the URL that corresponds to a set of route parameters and a route name.

(继承自 Control)
GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 URL。Gets the URL that corresponds to a set of route parameters and a route name.

(继承自 Control)
GetType()

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

(继承自 Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。Returns the prefixed portion of the UniqueID property of the specified control.

(继承自 Control)
HasControls()

确定服务器控件是否包含任何子控件。Determines if the server control contains any child controls.

(继承自 Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。Returns a value indicating whether events are registered for the control or any child controls.

(继承自 Control)
InitializePager(GridViewRow, Int32, PagedDataSource)

初始化在分页功能启用时显示的页导航行。Initializes the pager row displayed when the paging feature is enabled.

InitializeRow(GridViewRow, DataControlField[])

初始化 GridView 控件中的行。Initializes a row in the GridView control.

IsBindableType(Type)

确定指定的数据类型是否能绑定到 GridView 控件中的列。Determines whether the specified data type can be bound to a column in a GridView control.

IsLiteralContent()

确定服务器控件是否只包含文字内容。Determines if the server control holds only literal content.

(继承自 Control)
LoadControlState(Object)

加载 GridView 控件中需要保留的属性的状态(即使在 EnableViewState 属性设置为 false 时)。Loads the state of the properties in the GridView control that need to be persisted, even when the EnableViewState property is set to false.

LoadViewState(Object)

加载以前保存的 GridView 控件的视图状态。Loads the previously saved view state of the GridView control.

MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。Retrieves the physical path that a virtual path, either absolute or relative, maps to.

(继承自 Control)
MarkAsDataBound()

将视图状态中的控件状态设置为成功绑定到数据。Sets the state of the control in view state as successfully bound to data.

(继承自 DataBoundControl)
MemberwiseClone()

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

(继承自 Object)
MergeStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,但不覆盖该控件现有的任何样式元素。Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
OnBubbleEvent(Object, EventArgs)

确定 Web 服务器控件的事件是否沿页的用户界面 (UI) 服务器控件层次结构向上传递。Determines whether the event for the Web server control is passed up the page's user interface (UI) server control hierarchy.

OnCreatingModelDataSource(CreatingModelDataSourceEventArgs)

引发 CreatingModelDataSource 事件。Raises the CreatingModelDataSource event.

(继承自 DataBoundControl)
OnDataBinding(EventArgs)

引发 DataBinding 事件。Raises the DataBinding event.

(继承自 Control)
OnDataBound(EventArgs)

引发 DataBound 事件。Raises the DataBound event.

(继承自 BaseDataBoundControl)
OnDataPropertyChanged()

GridViewDataMemberDataSource 属性更改之后,将 DataSourceID 控件重新绑定至它的数据。Rebinds the GridView control to its data after the DataMember, DataSource, or DataSourceID property is changed.

OnDataSourceViewChanged(Object, EventArgs)

引发 DataSourceViewChanged 事件。Raises the DataSourceViewChanged event.

OnInit(EventArgs)

引发 Init 事件。Raises the Init event.

OnLoad(EventArgs)

处理 Load 事件。Handles the Load event.

(继承自 DataBoundControl)
OnPageIndexChanged(EventArgs)

引发 PageIndexChanged 事件。Raises the PageIndexChanged event.

OnPageIndexChanging(GridViewPageEventArgs)

引发 PageIndexChanging 事件。Raises the PageIndexChanging event.

OnPagePreLoad(Object, EventArgs)

在加载数据绑定控件之前设置该控件的初始化状态。Sets the initialized state of the data-bound control before the control is loaded.

OnPreRender(EventArgs)

引发 PreRender 事件。Raises the PreRender event.

OnRowCancelingEdit(GridViewCancelEditEventArgs)

引发 RowCancelingEdit 事件。Raises the RowCancelingEdit event.

OnRowCommand(GridViewCommandEventArgs)

引发 RowCommand 事件。Raises the RowCommand event.

OnRowCreated(GridViewRowEventArgs)

引发 RowCreated 事件。Raises the RowCreated event.

OnRowDataBound(GridViewRowEventArgs)

引发 RowDataBound 事件。Raises the RowDataBound event.

OnRowDeleted(GridViewDeletedEventArgs)

引发 RowDeleted 事件。Raises the RowDeleted event.

OnRowDeleting(GridViewDeleteEventArgs)

引发 RowDeleting 事件。Raises the RowDeleting event.

OnRowEditing(GridViewEditEventArgs)

引发 RowEditing 事件。Raises the RowEditing event.

OnRowUpdated(GridViewUpdatedEventArgs)

引发 RowUpdated 事件。Raises the RowUpdated event.

OnRowUpdating(GridViewUpdateEventArgs)

引发 RowUpdating 事件。Raises the RowUpdating event.

OnSelectedIndexChanged(EventArgs)

引发 SelectedIndexChanged 事件。Raises the SelectedIndexChanged event.

OnSelectedIndexChanging(GridViewSelectEventArgs)

引发 SelectedIndexChanging 事件。Raises the SelectedIndexChanging event.

OnSorted(EventArgs)

引发 Sorted 事件。Raises the Sorted event.

OnSorting(GridViewSortEventArgs)

引发 Sorting 事件。Raises the Sorting event.

OnUnload(EventArgs)

引发 Unload 事件。Raises the Unload event.

(继承自 Control)
OpenFile(String)

获取用于读取文件的 StreamGets a Stream used to read a file.

(继承自 Control)
PerformDataBinding(IEnumerable)

将指定数据源绑定到 GridView 控件。Binds the specified data source to the GridView control.

PerformSelect()

从关联的数据源中检索数据。Retrieves data from the associated data source.

(继承自 DataBoundControl)
PrepareControlHierarchy()

建立控件层次结构。Establishes the control hierarchy.

RaiseBubbleEvent(Object, EventArgs)

将所有事件源及其信息分配给控件的父级。Assigns any sources of the event and its information to the control's parent.

(继承自 Control)
RaiseCallbackEvent(String)

GetCallbackEventReference(Control, String, String, String, Boolean) 方法中的回调处理程序创建参数。Creates the arguments for the callback handler in the GetCallbackEventReference(Control, String, String, String, Boolean) method.

RaisePostBackEvent(String)

GridView 控件回发到服务器时引发此控件的合适的事件。Raises the appropriate events for the GridView control when it posts back to the server.

RemovedControl(Control)

Controls 对象的 Control 集合移除子控件后调用。Called after a child control is removed from the Controls collection of the Control object.

(继承自 Control)
Render(HtmlTextWriter)

使用指定的 HtmlTextWriter 对象将 Web 服务器控件内容呈现给客户端浏览器。Renders the Web server control content to the client's browser using the specified HtmlTextWriter object.

RenderBeginTag(HtmlTextWriter)

将控件的 HTML 开始标记呈现到指定的编写器中。Renders the HTML opening tag of the control to the specified writer. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client.

(继承自 Control)
RenderContents(HtmlTextWriter)

将控件的内容呈现到指定的编写器中。Renders the contents of the control to the specified writer. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

(继承自 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

(继承自 Control)
RenderEndTag(HtmlTextWriter)

将控件的 HTML 结束标记呈现到指定的编写器中。Renders the HTML closing tag of the control into the specified writer. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
ResolveAdapter()

获取负责呈现指定控件的控件适配器。Gets the control adapter responsible for rendering the specified control.

(继承自 Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。Gets a URL that can be used by the browser.

(继承自 Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。Converts a URL into one that is usable on the requesting client.

(继承自 Control)
SaveControlState()

保存 GridView 控件中需要保留的属性的状态(即使在 EnableViewState 属性设置为 false 时)。Saves the state of the properties in the GridView control that need to be persisted, even when the EnableViewState property is set to false.

SaveViewState()

加载以前保存的 GridView 控件的视图状态。Loads the previously saved view state of the GridView control.

SelectRow(Int32)

选择要在 GridView 控件中编辑的行。Selects the row to edit in a GridView control.

SetDesignModeState(IDictionary)

为控件设置设计时数据。Sets design-time data for a control.

(继承自 Control)
SetEditRow(Int32)

GridView 控件中使用指定行索引将某行置于编辑模式。Puts a row in edit mode in a GridView control by using the specified row index.

SetPageIndex(Int32)

使用行索引设置 GridView 控件的页索引。Sets the page index of the GridView control by using the row index.

SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。Assigns an event handler delegate to render the server control and its content into its parent control.

(继承自 Control)
SetTraceData(Object, Object)

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。Sets trace data for design-time tracing of rendering data, using the trace data key and the trace data value.

(继承自 Control)
SetTraceData(Object, Object, Object)

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。Sets trace data for design-time tracing of rendering data, using the traced object, the trace data key, and the trace data value.

(继承自 Control)
Sort(String, SortDirection)

根据指定的排序表达式和方向对 GridView 控件进行排序。Sorts the GridView control based on the specified sort expression and direction.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
TrackViewState()

跟踪 GridView 控件的视图状态更改,以便可以将更改存储在该控件的 StateBag 对象中。Tracks view-state changes to the GridView control so they can be stored in the control's StateBag object. 通过 ViewState 属性可访问此对象。This object is accessible through the ViewState property.

UpdateRow(Int32, Boolean)

使用行的字段值更新位于指定行索引位置的记录。Updates the record at the specified row index using the field values of the row.

ValidateDataSource(Object)

验证数据绑定控件绑定到的对象是否可以和该控件一同使用。Verifies that the object a data-bound control binds to is one it can work with.

(继承自 DataBoundControl)

事件

CallingDataMethods

在数据方法正被调用时发生。Occurs when data methods are being called.

(继承自 DataBoundControl)
CreatingModelDataSource

ModelDataSource 对象正被创建时发生。Occurs when the ModelDataSource object is being created.

(继承自 DataBoundControl)
DataBinding

当服务器控件绑定到数据源时发生。Occurs when the server control binds to a data source.

(继承自 Control)
DataBound

在服务器控件绑定到数据源后发生。Occurs after the server control binds to a data source.

(继承自 BaseDataBoundControl)
Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.

(继承自 Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。Occurs when the server control is initialized, which is the first step in its lifecycle.

(继承自 Control)
Load

当服务器控件加载到 Page 对象中时发生。Occurs when the server control is loaded into the Page object.

(继承自 Control)
PageIndexChanged

在单击某一页导航按钮时,但在 GridView 控件处理分页操作之后发生。Occurs when one of the pager buttons is clicked, but after the GridView control handles the paging operation.

PageIndexChanging

在单击某一页导航按钮时,但在 GridView 控件处理分页操作之前发生。Occurs when one of the pager buttons is clicked, but before the GridView control handles the paging operation.

PreRender

在加载 Control 对象之后、呈现之前发生。Occurs after the Control object is loaded but prior to rendering.

(继承自 Control)
RowCancelingEdit

单击编辑模式中某一行的“取消”按钮以后,在该行退出编辑模式之前发生。Occurs when the Cancel button of a row in edit mode is clicked, but before the row exits edit mode.

RowCommand

当单击 GridView 控件中的按钮时发生。Occurs when a button is clicked in a GridView control.

RowCreated

GridView 控件中创建行时发生。Occurs when a row is created in a GridView control.

RowDataBound

GridView 控件中将数据行绑定到数据时发生。Occurs when a data row is bound to data in a GridView control.

RowDeleted

在单击某一行的“删除”按钮时,但在 GridView 控件删除该行之后发生。Occurs when a row's Delete button is clicked, but after the GridView control deletes the row.

RowDeleting

在单击某一行的“删除”按钮时,但在 GridView 控件删除该行之前发生。Occurs when a row's Delete button is clicked, but before the GridView control deletes the row.

RowEditing

发生在单击某一行的“编辑”按钮以后,GridView 控件进入编辑模式之前。Occurs when a row's Edit button is clicked, but before the GridView control enters edit mode.

RowUpdated

发生在单击某一行的“更新”按钮,并且 GridView 控件对该行进行更新之后。Occurs when a row's Update button is clicked, but after the GridView control updates the row.

RowUpdating

发生在单击某一行的“更新”按钮以后,GridView 控件对该行进行更新之前。Occurs when a row's Update button is clicked, but before the GridView control updates the row.

SelectedIndexChanged

发生在单击某一行的“选择”按钮,GridView 控件对相应的选择操作进行处理之后。Occurs when a row's Select button is clicked, but after the GridView control handles the select operation.

SelectedIndexChanging

发生在单击某一行的“选择”按钮以后,GridView 控件对相应的选择操作进行处理之前。Occurs when a row's Select button is clicked, but before the GridView control handles the select operation.

Sorted

在单击用于列排序的超链接时,但在 GridView 控件对相应的排序操作进行处理之后发生。Occurs when the hyperlink to sort a column is clicked, but after the GridView control handles the sort operation.

Sorting

在单击用于列排序的超链接时,但在 GridView 控件对相应的排序操作进行处理之前发生。Occurs when the hyperlink to sort a column is clicked, but before the GridView control handles the sort operation.

Unload

当服务器控件从内存中卸载时发生。Occurs when the server control is unloaded from memory.

(继承自 Control)

显式接口实现

IAttributeAccessor.GetAttribute(String)

获取具有指定名称的 Web 控件的特性。Gets an attribute of the Web control with the specified name.

(继承自 WebControl)
IAttributeAccessor.SetAttribute(String, String)

将 Web 控件的特性设置为指定的名称和值。Sets an attribute of the Web control to the specified name and value.

(继承自 WebControl)
ICallbackContainer.GetCallbackScript(IButtonControl, String)

为执行排序操作的按钮创建回调脚本。Creates the callback script for a button that performs a sorting operation.

ICallbackEventHandler.GetCallbackResult()

返回以控件为目标的回调事件的结果。Returns the result of a callback event that targets a control.

ICallbackEventHandler.RaiseCallbackEvent(String)

GetCallbackEventReference(Control, String, String, String, Boolean) 方法中的回调处理程序创建参数。Creates the arguments for the callback handler in the GetCallbackEventReference(Control, String, String, String, Boolean) method.

IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参阅 ControlBuilderFor a description of this member, see ControlBuilder.

(继承自 Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参阅 GetDesignModeState()For a description of this member, see GetDesignModeState().

(继承自 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

有关此成员的说明,请参阅 SetDesignModeState(IDictionary)For a description of this member, see SetDesignModeState(IDictionary).

(继承自 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

有关此成员的说明,请参阅 SetOwnerControl(Control)For a description of this member, see SetOwnerControl(Control).

(继承自 Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参阅 UserDataFor a description of this member, see UserData.

(继承自 Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参阅 DataBindingsFor a description of this member, see DataBindings.

(继承自 Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参阅 HasDataBindingsFor a description of this member, see HasDataBindings.

(继承自 Control)
IDataBoundControl.DataKeyNames

获取或设置数据绑定控件中所显示项的主键字段的名称。Gets or sets the names of the primary key fields for the items displayed in a data-bound control.

IDataBoundControl.DataMember

获取或设置要绑定到数据绑定控件的数据源控件所公开的表。Gets or sets the table that is exposed by the data source control to bind to the data-bound control.

IDataBoundControl.DataSource

获取或设置数据绑定控件从中检索数据项列表的数据源对象。Gets or sets the data source object from which the data-bound control retrieves the list of data items.

IDataBoundControl.DataSourceID

获取或设置数据绑定控件从中检索数据项列表的数据源的 ID。Gets or sets the ID of the data source from which the data-bound control retrieves the list of data items.

IDataBoundControl.DataSourceObject

获取或设置数据绑定控件从中检索数据项列表的数据源对象。Gets or sets the data source object from which the data-bound control retrieves the list of data items.

IDataBoundListControl.ClientIDRowSuffix

获取或设置数据字段的名称,这些数据字段的值附加到 ClientID 属性值,以便唯一标识数据绑定控件的每个实例。Gets or sets the names of the data fields whose values are appended to the ClientID property value to uniquely identify each instance of a data-bound control.

IDataBoundListControl.DataKeys

获取对象的集合,这些对象表示数据绑定控件中的 DataKeys 值。Gets a collection of objects that represent the DataKeys value in a data-bound control.

IDataBoundListControl.EnablePersistedSelection

获取或设置一个值,该值指示行的选择是基于索引还是数据键值。Gets or sets a value that indicates whether the selection of a row is based on index or on data-key values.

IDataBoundListControl.SelectedDataKey

获取一个对象,其中包含数据绑定控件中所选行的数据键值。Gets the object that contains the data key value for the selected row in a data-bound control.

IDataBoundListControl.SelectedIndex

获取或设置数据绑定控件中所选行的索引。Gets or sets the index of the selected row in the data-bound control.

IDataKeysControl.ClientIDRowSuffixDataKeys

获取数据值,在 ASP.NET 生成 ClientID 值时,这些数据值用于唯一标识数据绑定控件的每个实例。Gets the data values that are used to uniquely identify each instance of a data-bound control when ASP.NET generates the ClientID value.

IExpressionsAccessor.Expressions

有关此成员的说明,请参阅 ExpressionsFor a description of this member, see Expressions.

(继承自 Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参阅 HasExpressionsFor a description of this member, see HasExpressions.

(继承自 Control)
IFieldControl.FieldsGenerator

获取或设置一个控件,该控件自动为数据绑定控件生成列,供 ASP.NET 动态数据使用。Gets or sets the control that automatically generates the columns for a data-bound control for use by ASP.NET Dynamic Data.

IParserAccessor.AddParsedSubObject(Object)

有关此成员的说明,请参阅 AddParsedSubObject(Object)For a description of this member, see AddParsedSubObject(Object).

(继承自 Control)
IPersistedSelector.DataKey

有关此成员的说明,请参阅 DataKeyFor a description of this member, see DataKey.

IPostBackContainer.GetPostBackOptions(IButtonControl)

创建一个 PostBackOptions 对象,该对象表示指定的按钮控件的回发行为。Creates a PostBackOptions object that represents the postback behavior of the specified button control.

IPostBackEventHandler.RaisePostBackEvent(String)

GridView 控件回发到服务器时引发此控件的合适的事件。Raises the appropriate events for the GridView control when it posts back to the server.

扩展方法

EnablePersistedSelection(BaseDataBoundControl)

使选定内容能够保留在支持选择和分页的数据控件中。Enables selection to be persisted in data controls that support selection and paging.

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。Returns the data source that is associated with the data control for the specified control.

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。Returns the field template for the specified column in the specified control's naming container.

FindMetaTable(Control)

返回包含数据控件的元表对象。Returns the metatable object for the containing data control.

GetDefaultValues(INamingContainer)

为指定数据控件获取默认值的集合。Gets the collection of the default values for the specified data control.

GetMetaTable(INamingContainer)

为指定数据控件获取表元数据。Gets the table metadata for the specified data control.

SetMetaTable(INamingContainer, MetaTable)

为指定数据控件设置表元数据。Sets the table metadata for the specified data control.

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

为指定数据控件设置表元数据和默认值映射。Sets the table metadata and default value mapping for the specified data control.

SetMetaTable(INamingContainer, MetaTable, Object)

为指定数据控件设置表元数据和默认值映射。Sets the table metadata and default value mapping for the specified data control.

TryGetMetaTable(INamingContainer, MetaTable)

确定表元数据是否可用。Determines whether table metadata is available.

EnableDynamicData(INamingContainer, Type)

为指定数据控件启用动态数据行为。Enables Dynamic Data behavior for the specified data control.

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

为指定数据控件启用动态数据行为。Enables Dynamic Data behavior for the specified data control.

EnableDynamicData(INamingContainer, Type, Object)

为指定数据控件启用动态数据行为。Enables Dynamic Data behavior for the specified data control.

适用于

另请参阅