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>
注解
当ModeChangingDetailsView控件尝试在编辑、插入和只读模式之间更改,但在模式实际更改之前,将引发 该事件。 这允许你提供一个事件处理程序,用于执行自定义例程,例如,每当发生此事件时,为特定模式配置 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) |