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 屬性中包含的 Row 物件屬性 GridViewRow 。 您也可以使用 RowType 物件的 屬性,判斷 (標頭資料列、資料列等) 所建立的資料 GridViewRow 列類型。

如需如何處理事件的詳細資訊,請參閱 處理和引發事件

如需 實例 GridViewRowEventArgs 的初始屬性值清單,請參閱 建 GridViewRowEventArgs 構函式。

建構函式

GridViewRowEventArgs(GridViewRow)

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

屬性

Row

取得所建立或繫結到資料的資料列。

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於

另請參閱