DetailsView.ModeChanging イベント
定義
DetailsView コントロールが編集、挿入、および読み取り専用の各モード間の切り替えを行おうとした場合に、CurrentMode プロパティの更新前に発生します。Occurs when a DetailsView control attempts to change between edit, insert, and read-only mode, but before the CurrentMode property is updated.
public:
event System::Web::UI::WebControls::DetailsViewModeEventHandler ^ ModeChanging;
public event System.Web.UI.WebControls.DetailsViewModeEventHandler ModeChanging;
member this.ModeChanging : System.Web.UI.WebControls.DetailsViewModeEventHandler
Public Custom Event ModeChanging As DetailsViewModeEventHandler
イベントの種類
例
次のコード例は、 ModeChanging コントロールが編集モードのときにイベントを使用してページング機能を無効にする方法を示して DetailsView います。The following code example demonstrates how to use the ModeChanging event to disable the paging feature when the DetailsView control is in edit mode.
<%@ 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 CustomerDetailView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
{
// Disable the paging feature in edit mode.
if (e.NewMode == DetailsViewMode.Edit)
{
CustomerDetailView.AllowPaging = false;
}
else
{
CustomerDetailView.AllowPaging = true;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView ModeChanging Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView ModeChanging Example</h3>
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneraterows="true"
autogenerateeditbutton="true"
allowpaging="true"
onmodechanging="CustomerDetailView_ModeChanging"
runat="server">
<fieldheaderstyle backcolor="Navy"
forecolor="White"/>
</asp:detailsview>
<!-- 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" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub CustomerDetailView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
' Disable the paging feature in edit mode.
If e.NewMode = DetailsViewMode.Edit Then
CustomerDetailView.AllowPaging = False
Else
CustomerDetailView.AllowPaging = True
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView ModeChanging Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView ModeChanging Example</h3>
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneraterows="true"
autogenerateeditbutton="true"
allowpaging="true"
onmodechanging="CustomerDetailView_ModeChanging"
runat="server">
<fieldheaderstyle backcolor="Navy"
forecolor="White"/>
</asp:detailsview>
<!-- 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" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
注釈
イベントは、 ModeChanging DetailsView コントロールが編集、挿入、および読み取り専用モードを変更しようとしたときに、 CurrentMode プロパティが更新される前に発生します。The ModeChanging event is raised when a DetailsView control attempts to change between edit, insert, and read-only mode, but before the CurrentMode property is updated. これにより、このイベントが発生するたびに、モードの変更をキャンセルするなどのカスタムルーチンを実行するイベントハンドラーを提供できます。This allows you to provide an event handler that performs a custom routine, such as canceling the mode change, whenever this event occurs.
DetailsViewModeEventArgsオブジェクトがイベントハンドラーに渡されます。これにより、新しいモードを決定し、ユーザーが編集操作をキャンセルした結果としてモードが変更されたかどうかを判断したり、モードの変更を取り消したりすることができます。A DetailsViewModeEventArgs object is passed to the event handler, which allows you to determine the new mode, to determine whether the mode change was a result of the user canceling an edit operation, or to cancel the mode change. 新しいモードを確認するには、プロパティを使用し NewMode ます。To determine the new mode, use the NewMode property. ユーザーが編集操作をキャンセルした結果としてモードが変更されたかどうかを確認するには、プロパティを使用し CancelingEdit ます。To determine whether the mode change was a result of the user canceling an edit operation, use the CancelingEdit property. モードの変更は、プロパティをに設定することによって取り消すことができ Cancel true
ます。You can cancel the mode change by setting the Cancel property to true
.
イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。For more information about how to handle events, see Handling and Raising Events.