Aggiornamento: novembre 2007
Si verifica quando una riga di dati viene associata a dati in un controllo GridView.
Spazio dei nomi:
System.Web.UI.WebControls Assembly:
System.Web (in System.Web.dll)
Visual Basic - (Dichiarazione)
Public Event RowDataBound As GridViewRowEventHandler
Dim instance As GridView
Dim handler As GridViewRowEventHandler
AddHandler instance.RowDataBound, handler
public event GridViewRowEventHandler RowDataBound
public:
event GridViewRowEventHandler^ RowDataBound {
void add (GridViewRowEventHandler^ value);
void remove (GridViewRowEventHandler^ value);
}
/** @event */
public void add_RowDataBound (GridViewRowEventHandler value)
/** @event */
public void remove_RowDataBound (GridViewRowEventHandler value)
JScript non supporta gli eventi.
<asp:GridView OnRowDataBound="GridViewRowEventHandler" />
Prima che possa essere eseguito il rendering del controllo GridView, ogni riga del controllo deve essere associata a un record dell'origine dati. L'evento RowDataBound viene generato quando una riga di dati, rappresentata da un oggetto GridViewRow, viene associata a dati nel controllo GridView. In questo modo è possibile fornire un metodo di gestione degli eventi in grado di eseguire una routine personalizzata, ad esempio la modifica dei valori dei dati associati alla riga, ogni volta che si verifica l'evento.
Un oggetto GridViewRowEventArgs viene passato al metodo di gestione degli eventi ed è quindi possibile accedere alle proprietà della riga che verrà associata. Per accedere a una cella specifica della riga, utilizzare la proprietà Cells dell'oggetto GridViewRow contenuto nella proprietà Row dell'oggetto GridViewRowEventArgs. È possibile determinare il tipo di riga da associare, ad esempio riga dell'intestazione, di dati e così via, utilizzando la proprietà RowType.
Per ulteriori informazioni sulla gestione degli eventi, vedere Utilizzo degli eventi.
Nell'esempio riportato di seguito viene illustrato come utilizzare l'evento RowDataBound per la modifica del valore di un campo nell'origine dati prima che venga visualizzato in un controllo GridView.
<%@ 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 >
<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="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 >
<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>
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition , Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Informazioni sulla versione
.NET Framework
Supportato in: 3.5, 3.0, 2.0
Riferimenti
Altre risorse