SqlDataSourceView.Updated 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於更新作業已經完成時。
public:
event System::Web::UI::WebControls::SqlDataSourceStatusEventHandler ^ Updated;
public event System.Web.UI.WebControls.SqlDataSourceStatusEventHandler Updated;
member this.Updated : System.Web.UI.WebControls.SqlDataSourceStatusEventHandler
Public Custom Event Updated As SqlDataSourceStatusEventHandler
事件類型
範例
下列程式碼範例示範如何顯示和更新控制項中 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>
備註
處理 事件, Updated 以在更新作業完成之後檢查輸出參數的值。 輸出參數可從與事件相關聯的 物件取得 SqlDataSourceStatusEventArgs 。
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。