DetailsViewModeEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 ModeChanging 事件的資料。
public ref class DetailsViewModeEventArgs : System::ComponentModel::CancelEventArgs
public class DetailsViewModeEventArgs : System.ComponentModel.CancelEventArgs
type DetailsViewModeEventArgs = class
inherit CancelEventArgs
Public Class DetailsViewModeEventArgs
Inherits CancelEventArgs
- 繼承
範例
下列程式碼範例示範如何在控制項轉換成編輯模式時 DetailsView ,使用 DetailsViewModeEventArgs 傳遞至事件處理常式 ModeChanging 的物件來隱藏呼叫器資料列。
<%@ 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 CustomerDetailsView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
{
// Use the NewMode property to determine the mode to which the
// DetailsView control is transitioning.
switch (e.NewMode)
{
case DetailsViewMode.Edit:
// Hide the pager row and clear the Label control
// when transitioning to edit mode.
CustomerDetailsView.AllowPaging = false;
MessageLabel.Text = "";
break;
case DetailsViewMode.ReadOnly:
// Display the pager row and confirmation message
// when transitioning to edit mode.
CustomerDetailsView.AllowPaging = true;
if (e.CancelingEdit)
{
MessageLabel.Text = "Update canceled.";
}
else
{
MessageLabel.Text = "Update completed.";
}
break;
case DetailsViewMode.Insert:
// Cancel the mode change if the DetailsView
// control attempts to transition to insert
// mode.
e.Cancel = true;
break;
default:
MessageLabel.Text = "Unsupported mode.";
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsViewModeEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewModeEventArgs Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneraterows="true"
autogenerateeditbutton="true"
allowpaging="true"
onmodechanging="CustomerDetailsView_ModeChanging"
runat="server">
</asp:detailsview>
<br/><br/>
<asp:label id="MessageLabel"
forecolor="Red"
runat="server"/>
<!-- 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="DetailsViewSource"
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"/>
</form>
</body>
</html>
<%@ Page language="VB" autoeventwireup="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub CustomerDetailsView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs) Handles CustomerDetailsView.ModeChanging
' Use the NewMode property to determine the mode to which the
' DetailsView control is transitioning.
Select Case e.NewMode
Case DetailsViewMode.Edit
' Hide the pager row and clear the Label control
' when transitioning to edit mode.
CustomerDetailsView.AllowPaging = False
MessageLabel.Text = ""
Case DetailsViewMode.ReadOnly
' Display the pager row and confirmation message
' when transitioning to edit mode.
CustomerDetailsView.AllowPaging = True
If e.CancelingEdit Then
MessageLabel.Text = "Update canceled."
Else
MessageLabel.Text = "Update completed."
End If
Case DetailsViewMode.Insert
' Cancel the mode change if the DetailsView
' control attempts to transition to insert
' mode.
e.Cancel = True
Case Else
MessageLabel.Text = "Unsupported mode."
End Select
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsViewModeEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewModeEventArgs Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneraterows="true"
autogenerateeditbutton="true"
allowpaging="true"
runat="server">
</asp:detailsview>
<br/><br/>
<asp:label id="MessageLabel"
forecolor="Red"
runat="server"/>
<!-- 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="DetailsViewSource"
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"/>
</form>
</body>
</html>
備註
ModeChanging當 DetailsView 控制項嘗試在編輯、插入和唯讀模式之間變更,但在模式實際變更之前,就會引發 事件。 這可讓您提供執行自訂常式的事件處理常式,例如 DetailsView ,每當發生此事件時,設定特定模式的控制項或取消模式變更。
DetailsViewModeEventArgs物件會傳遞至事件處理常式,可讓您判斷控制項正在變更的模式 DetailsView 、判斷事件是否 ModeChanging 因使用者取消編輯作業而引發,或表示應該取消插入作業。 若要判斷新的模式,請使用 NewMode 屬性。 您也可以將 NewMode 屬性設定為其中 DetailsViewMode 一個列舉值,以使用 屬性來變更為替代模式。
CancelingEdit使用 屬性來判斷使用者是否已取消編輯作業。 若要取消插入作業,請將 Cancel 屬性設定為 true
。
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。
如需 DetailsViewModeEventArgs 類別之執行個體的初始屬性值清單,請參閱 DetailsViewModeEventArgs 建構函式。
建構函式
DetailsViewModeEventArgs(DetailsViewMode, Boolean) |
初始化 DetailsViewModeEventArgs 類別的新執行個體。 |
屬性
Cancel |
取得或設定值,這個值表示是否應該取消事件。 (繼承來源 CancelEventArgs) |
CancelingEdit |
取得值,指出 ModeChanging 事件的引發是否為使用者取消編輯作業的結果。 |
NewMode |
取得或設定 DetailsView 控制項要變更為何種模式。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |