GridViewRowEventArgs 类

定义

提供有关 RowCreatedRowDataBound 事件的数据。Provides data for the RowCreated and RowDataBound events.

public ref class GridViewRowEventArgs : EventArgs
public class GridViewRowEventArgs : EventArgs
type GridViewRowEventArgs = class
    inherit EventArgs
Public Class GridViewRowEventArgs
Inherits EventArgs
继承
GridViewRowEventArgs

示例

下面的示例演示如何使用GridViewRowEventArgs传递给事件处理方法的对象访问绑定到数据的行的属性。The following example demonstrates how to use the GridViewRowEventArgs object passed to the event-handling method to access the properties of the row being bound to data.


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
        
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // Display the company name in italics.
      e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
        
    }
    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView RowDataBound Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView RowDataBound Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        onrowdatabound="CustomersGridView_RowDataBound" 
        runat="server">
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
            
    </form>
  </body>
</html>


<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow Then
    
      ' Display the company name in italics.
      e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>"
        
    End If
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView RowDataBound Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView RowDataBound Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        onrowdatabound="CustomersGridView_RowDataBound" 
        runat="server">
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
            
    </form>
  </body>
</html>

注解

在呈现GridViewRow控件之前, 必须为控件中的每一行创建一个对象。 GridViewBefore the GridView control can be rendered, a GridViewRow object must be created for each row in the control. 每次创建GridView控件中的行时都会引发事件。RowCreatedThe RowCreated event is raised each time a row in the GridView control is created. 这使你可以提供一种事件处理方法, 该方法可在每次发生此事件时执行自定义例程 (如将自定义内容添加到行)。This allows you to provide an event-handling method that performs a custom routine, such as adding custom content to a row, whenever this event occurs.

同样, 控件中的每一行都必须绑定到数据源中的记录, 然后GridView才能呈现控件。Similarly, each row in the control must be bound to a record in the data source before the GridView control can be rendered. RowDataBound数据行 ( GridViewRow由对象表示) GridView绑定到控件中的数据时, 将引发事件。The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. 这使你可以提供一种事件处理方法, 该方法可在每次发生此事件时执行自定义例程 (如修改绑定到行的数据的值)。This allows you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.

GridViewRowEventArgs对象传递给事件处理方法, 该方法允许您访问引发事件的行的属性。A GridViewRowEventArgs object is passed to the event-handling method, which allows you to access the properties of the row that raised the event. 若要访问行中的特定单元, 请使用Cells Row属性中包含GridViewRow的对象的属性。To access a specific cell in the row, use the Cells property of the GridViewRow object contained in the Row property. 您还可以通过使用RowType GridViewRow对象的属性来确定要创建的行类型 (标题行、数据行等)。You can also determine which row type (header row, data row, and so on) is being created by using the RowType property of the GridViewRow object.

有关如何处理事件的详细信息, 请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

有关实例GridViewRowEventArgs的初始属性值的列表, GridViewRowEventArgs请参见构造函数。For a list of initial property values for an instance of GridViewRowEventArgs, see the GridViewRowEventArgs constructor.

构造函数

GridViewRowEventArgs(GridViewRow)

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

属性

Row

获取要创建或数据绑定的行。Gets the row being created or data-bound.

方法

Equals(Object)

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

(继承自 Object)
GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅