SqlDataSource.Updated Event
.NET Framework 3.0
Occurs when an update operation has completed.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
SqlDataSource Members
System.Web.UI.WebControls Namespace
Updating
OnUpdated
Update
SqlDataSource.UpdateParameters Property
Data Source Web Server Controls
SqlDataSource Web Server Control Overview
Introduction to the ASP.NET Page Life Cycle
Assembly: System.Web (in system.web.dll)
Handle the Updated event to examine the values of output parameters after an update operation has completed. The output parameters are available from the SqlDataSourceStatusEventArgs object that is associated with the event.
For more information about handling events, see Consuming Events.
The following code example demonstrates how to display and update data that is retrieved from an ODBC database in a GridView control. After a record is successfully updated, the Updated event is handled by an event handler to perform a post-processing step where an e-mail notification is sent.
<%@Page Language="C#" %> <%@Import Namespace="System.Web.Mail" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void OnDSUpdatedHandler(Object source, SqlDataSourceStatusEventArgs e) { if (e.AffectedRows > 0) { // Perform any additional processing, such as sending an e-mail notification. Label1.Text = Request.LogonUserIdentity.Name + " changed user information sucessfully!"; } else { Label1.Text = "No data updated!"; } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>ASP.NET Example</title> </head> <body> <!-- This example uses a Northwind database that is hosted by an ODBC-compliant database. To run this sample, create an ODBC DSN to any database that hosts the Northwind database, including Microsoft SQL Server or Microsoft Access, change the name of the DSN in the ConnectionString, and view the page. --> <form id="form1" runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" ProviderName="System.Data.Odbc" DataSourceMode="DataSet" ConnectionString="dsn=myodbc3dsn;" SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees" UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=?" OnUpdated="OnDSUpdatedHandler"> </asp:SqlDataSource> <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" AutoGenerateEditButton="True" DataSourceID="SqlDataSource1"> <columns> <asp:BoundField HeaderText="First Name" DataField="FirstName" /> <asp:BoundField HeaderText="Last Name" DataField="LastName" /> <asp:BoundField HeaderText="Title" DataField="Title" /> </columns> </asp:GridView> <asp:Label id="Label1" runat="server"> </asp:Label> </form> </body> </html>
<%@Page Language="VJ#" %> <%@Import Namespace="System.Web.Mail" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void OnDSUpdatedHandler(Object source, SqlDataSourceStatusEventArgs e) { if (e.get_AffectedRows() > 0) { // Perform any additional processing, such as sending an e-mail notification. Label1.set_Text(get_Request().get_LogonUserIdentity().get_Name() + " changed user information successfully!"); } else { Label1.set_Text("No data updated!"); } } //OnDSUpdatedHandler </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>ASP.NET Example</title> </head> <body> <!-- This example uses a Northwind database that is hosted by an ODBC-compliant database. To run this sample, create an ODBC DSN to any database that hosts the Northwind database, including Microsoft SQL Server or Microsoft Access, change the name of the DSN in the ConnectionString, and view the page. --> <form id="form1" runat="server"> <asp:SqlDataSource id="SqlDataSource1" runat="server" ProviderName="System.Data.Odbc" DataSourceMode="DataSet" ConnectionString="dsn=myodbc3dsn;" SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees" UpdateCommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=?" OnUpdated="OnDSUpdatedHandler"> </asp:SqlDataSource> <asp:GridView id="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" AutoGenerateEditButton="True" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField HeaderText="First Name" DataField="FirstName" /> <asp:BoundField HeaderText="Last Name" DataField="LastName" /> <asp:BoundField HeaderText="Title" DataField="Title" /> </Columns> </asp:GridView> <asp:Label id="Label1" runat="server"> </asp:Label> </form> </body> </html>
Reference
SqlDataSource ClassSqlDataSource Members
System.Web.UI.WebControls Namespace
Updating
OnUpdated
Update
SqlDataSource.UpdateParameters Property
Other Resources
ASP.NET Data Access OverviewData Source Web Server Controls
SqlDataSource Web Server Control Overview
Introduction to the ASP.NET Page Life Cycle