SqlDataSourceView.OnUpdated(SqlDataSourceStatusEventArgs) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
Updated 控件完成更新操作后引发 SqlDataSource 事件。
protected:
virtual void OnUpdated(System::Web::UI::WebControls::SqlDataSourceStatusEventArgs ^ e);
protected virtual void OnUpdated (System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e);
abstract member OnUpdated : System.Web.UI.WebControls.SqlDataSourceStatusEventArgs -> unit
override this.OnUpdated : System.Web.UI.WebControls.SqlDataSourceStatusEventArgs -> unit
Protected Overridable Sub OnUpdated (e As SqlDataSourceStatusEventArgs)
参数
示例
下面的代码示例演示如何在 控件中 GridView 显示和更新从 ODBC 数据库检索到的数据。 成功更新记录后, Updated 事件处理程序将处理该事件,以执行发送电子邮件通知的后处理步骤。
<%@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 email notification.
Label1.Text = Request.LogonUserIdentity.Name +
" changed user information successfully!";
}
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="VB" %>
<%@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">
Sub OnDSUpdatedHandler(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
If e.AffectedRows > 0 Then
' Perform any additional processing, such as setting a status label.
Label1.Text = Request.LogonUserIdentity.Name & _
" changed user information successfully!"
Else
Label1.Text = "No data updated!"
End If
End Sub '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>
注解
引发事件时,将通过委托调用事件处理程序。 有关如何处理事件的详细信息,请参阅 处理和引发事件。
OnUpdated 方法还允许派生类对事件进行处理而不必附加委托。 这是在派生类中处理事件的首选技术。
继承者说明
在派生类中重写 OnUpdated(SqlDataSourceStatusEventArgs) 方法时,请务必为基类调用 OnUpdated(SqlDataSourceStatusEventArgs) 方法,以便注册的委托接收 事件。