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>

備註

GridView 可以轉譯控制項之前,必須為 GridViewRow 控制項中的每個資料列建立物件。Before the GridView control can be rendered, a GridViewRow object must be created for each row in the control. RowCreated每次建立控制項中的資料列時,就會引發此事件 GridViewThe 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 至控制項中的資料時,就會引發事件 GridViewThe 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. 若要存取資料列中的特定資料格,請使用屬性(property)中所 Cells 包含之物件的屬性(property) GridViewRow RowTo access a specific cell in the row, use the Cells property of the GridViewRow object contained in the Row property. 您也可以使用物件的屬性,判斷要建立 (標頭資料列、資料列等) 的資料列類型 RowType GridViewRowYou 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 ,請參閱函式 GridViewRowEventArgsFor 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()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱