Share via


GridViewRowEventArgs Kelas

Definisi

Menyediakan data untuk peristiwa RowCreated dan RowDataBound.

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

Contoh

Contoh berikut menunjukkan cara menggunakan objek yang GridViewRowEventArgs diteruskan ke metode penanganan peristiwa untuk mengakses properti baris yang terikat ke 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>

Keterangan

GridView Sebelum kontrol dapat dirender, GridViewRow objek harus dibuat untuk setiap baris dalam kontrol. Peristiwa RowCreated dimunculkan setiap kali baris dalam GridView kontrol dibuat. Ini memungkinkan Anda untuk menyediakan metode penanganan peristiwa yang melakukan rutinitas kustom, seperti menambahkan konten kustom ke baris, setiap kali peristiwa ini terjadi.

Demikian pula, setiap baris dalam kontrol harus terikat ke rekaman di sumber data sebelum GridView kontrol dapat dirender. Peristiwa RowDataBound dimunculkan ketika baris data (diwakili oleh GridViewRow objek) terikat ke GridView data dalam kontrol. Ini memungkinkan Anda untuk menyediakan metode penanganan peristiwa yang melakukan rutinitas kustom, seperti memodifikasi nilai data yang terikat ke baris, setiap kali peristiwa ini terjadi.

Objek GridViewRowEventArgs diteruskan ke metode penanganan peristiwa, yang memungkinkan Anda mengakses properti baris yang menaikkan peristiwa. Untuk mengakses sel tertentu dalam baris, gunakan Cells properti objek yang GridViewRow terkandung dalam Row properti . Anda juga dapat menentukan jenis baris mana (baris header, baris data, dan sebagainya) yang sedang dibuat dengan menggunakan RowType properti GridViewRow objek .

Untuk informasi selengkapnya tentang cara menangani peristiwa, lihat Menangani dan Menaikkan Peristiwa.

Untuk daftar nilai properti awal untuk instans GridViewRowEventArgs, lihat GridViewRowEventArgs konstruktor.

Konstruktor

GridViewRowEventArgs(GridViewRow)

Menginisialisasi instans baru kelas GridViewRowEventArgs.

Properti

Row

Mendapatkan baris yang sedang dibuat atau terikat data.

Metode

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk

Lihat juga