GridViewRowEventArgs 类

定义

提供有关 RowCreatedRowDataBound 事件的数据。

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

示例

以下示例演示如何使用 GridViewRowEventArgs 传递给事件处理方法的对象来访问绑定到数据的行的属性。


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

注解

GridView必须先为控件中的每一行创建对象GridViewRow,然后才能呈现控件。 RowCreated每次在控件中创建行时都会GridView引发 该事件。 这样,就可以提供一个事件处理方法,该方法在发生此事件时执行自定义例程,例如将自定义内容添加到行。

同样,控件中的每个行都必须绑定到数据源中的记录,然后 GridView 才能呈现控件。 RowDataBound当对象表示GridViewRow的数据行 () 绑定到控件中的数据时,将引发 该GridView事件。 这允许你提供一个事件处理方法,该方法执行自定义例程,例如,每当发生此事件时,修改绑定到行的数据的值。

对象 GridViewRowEventArgs 将传递给事件处理方法,该方法允许访问引发事件的行的属性。 若要访问行中的特定单元格,请使用 Cells 属性 GridViewRow 中包含的 Row 对象的 属性。 还可以使用 RowType 对象的 属性 GridViewRow 确定要创建的行类型) (标题行、数据行等。

有关如何处理事件的详细信息,请参阅 处理和引发事件

有关 实例 GridViewRowEventArgs的初始属性值列表, GridViewRowEventArgs 请参阅 构造函数。

构造函数

GridViewRowEventArgs(GridViewRow)

初始化 GridViewRowEventArgs 类的新实例。

属性

Row

获取要创建或数据绑定的行。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅