GridView.RowUpdated (Evento)
Ensamblado: System.Web (en system.web.dll)
El evento RowUpdated se produce cuando se hace clic en el botón Actualizar de una fila, pero después de que el control GridView actualice la fila. Esto permite proporcionar un método de control de eventos que realice una rutina personalizada, como comprobar los resultados de la operación de actualización, siempre que se produzca este evento.
Se pasa un objeto GridViewUpdatedEventArgs al método de control de eventos, lo que permite determinar el número de filas afectadas y las excepciones que se hayan producido. También puede indicar si la excepción se ha controlado en el método de control de eventos al establecer la propiedad ExceptionHandled del objeto GridViewUpdatedEventArgs.
Para obtener más información sobre la forma de controlar eventos, vea Utilizar eventos.
En el ejemplo de código siguiente se muestra cómo utilizar el evento RowUpdated para comprobar el resultado de la operación de actualización. Se muestra un mensaje para indicar al usuario si la operación se ha realizado correctamente.
<%@ 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_RowUpdated(Object sender, GridViewUpdatedEventArgs e) { // Indicate whether the update operation succeeded. if(e.Exception == null) { Message.Text = "Row updated successfully."; } else { e.ExceptionHandled = true; Message.Text = "An error occurred while attempting to update the row."; } } void CustomersGridView_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e) { // The update operation was canceled. Clear the message label. Message.Text = ""; } void CustomersGridView_RowEditing(Object sender, GridViewEditEventArgs e) { // The GridView control is entering edit mode. Clear the message label. Message.Text = ""; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridView RowUpdated Example</title> </head> <body> <form id="form1" runat="server"> <h3>GridView RowUpdated Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" onrowupdated="CustomersGridView_RowUpdated" onrowcancelingedit="CustomersGridView_RowCancelingEdit" onrowediting="CustomersGridView_RowEditing" 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]" updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.Referencia
GridView (Clase)GridView (Miembros)
System.Web.UI.WebControls (Espacio de nombres)
GridViewUpdatedEventArgs
GridView.AutoGenerateEditButton (Propiedad)
OnRowUpdated
GridView.RowCancelingEdit (Evento)
OnRowCancelingEdit
GridView.RowDeleted (Evento)
OnRowDeleted
GridView.RowDeleting (Evento)
OnRowDeleting
GridView.RowEditing (Evento)
OnRowEditing
RowUpdating
OnRowUpdating