FormView.CurrentMode プロパティ
アセンブリ: System.Web (system.web.dll 内)


CurrentMode プロパティを使用して、FormView コントロールが編集、挿入、または読み取り専用のいずれのモードであるかを確認します。さまざまなモード値の一覧を次の表に示します。
FormViewMode.Edit | |
FormViewMode.Insert | FormView コントロールは挿入モードになっています。この場合、ユーザーは、データ ソースに新しいレコードを追加できます。 |
FormView.ReadOnly |
この値は通常、New、Delete、または Cancel の各ボタンがクリックされたときに、FormView コントロールによって自動的に設定されます。操作への応答として FormView コントロールがモードを変更すると、次の表のイベントが発生します。これにより、イベントが発生したときに適切なルーチンを実行するカスタム イベント ハンドラを作成できます。
ModeChanged | FormView コントロールがモードを変更した場合に、モードの変更後に発生します。このイベントは通常、FormView コントロールがモードを変更するたびにタスクを実行する場合に使用されます。 |
ModeChanging | FormView コントロールがモードを変更した場合に、モードの変更前に発生します。このイベントは通常、モードの変更をキャンセルする場合に使用されます。 |
メモ ChangeMode メソッドを使用してプログラムによって モードを変更した場合、これらのイベントは発生しません。

CurrentMode プロパティを使用して、FormView コントロールが編集、挿入、または読み取り専用のいずれのモードであるかを確認する方法を次の例に示します。FormView コントロールが編集モードになっているときにユーザーが別のレコードに移動しようとすると、ページング操作はキャンセルされます。
<%@ Page language="VB" %> <script runat="server"> Sub EmployeeFormView_OnPageIndexChanging(ByVal sender As Object, ByVal e As FormViewPageEventArgs) ' Cancel the paging operation if the user attempts to navigate ' to another record while the FormView control is in edit mode. If EmployeeFormView.CurrentMode = FormViewMode.Edit Then e.Cancel = True MessageLabel.Text = _ "Please complete the update operation before navigating to another record." End If End Sub Sub EmployeeFormView_OnModeChanged(ByVal sender As Object, ByVal e As EventArgs) ' Clear the message label. MessageLabel.Text = "" End Sub </script> <html> <body> <form runat="server"> <h3>FormView Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" emptydatatext="No employees found." onpageindexchanging="EmployeeFormView_OnPageIndexChanging" onmodechanged="EmployeeFormView_OnModeChanged" runat="server"> <rowstyle backcolor="LightGreen" wrap="false"/> <editrowstyle backcolor="LightBlue" wrap="false"/> <itemtemplate> <table> <tr> <td rowspan="4"> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td colspan="2"> </td> </tr> <tr> <td> <b>Name:</b> </td> <td> <%# Eval("FirstName") %> <%# Eval("LastName") %> </td> </tr> <tr> <td> <b>Title:</b> </td> <td> <%# Eval("Title") %> </td> </tr> <tr> <td colspan="2"> <asp:linkbutton id="Edit" text="Edit" commandname="Edit" runat="server"/> </td> </tr> </table> </itemtemplate> <edititemtemplate> <table> <tr> <td rowspan="4"> <asp:image id="EmployeeEditImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td colspan="2"> </td> </tr> <tr> <td> <b>Name:</b> </td> <td> <asp:textbox id="FirstNameUpdateTextBox" text='<%# Bind("FirstName") %>' runat="server"/> <asp:textbox id="LastNameUpdateTextBox" text='<%# Bind("LastName") %>' runat="server"/> </td> </tr> <tr> <td> <b>Title:</b> </td> <td> <asp:textbox id="TitleUpdateTextBox" text='<%# Bind("Title") %>' runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:linkbutton id="UpdateButton" text="Update" commandname="Update" runat="server"/> <asp:linkbutton id="CancelButton" text="Cancel" commandname="Cancel" runat="server"/> </td> </tr> </table> </edititemtemplate> </asp:formview> <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="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]" updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title Where [EmployeeID]=@EmployeeID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void EmployeeFormView_OnPageIndexChanging(Object sender, FormViewPageEventArgs e) { // Cancel the paging operation if the user attempts to navigate // to another record while the FormView control is in edit mode. if (EmployeeFormView.CurrentMode == FormViewMode.Edit) { e.Cancel = true; MessageLabel.Text = "Please complete the update operation before navigating to another record."; } } void EmployeeFormView_OnModeChanged(Object sender, EventArgs e) { // Clear the message label. MessageLabel.Text = ""; } </script> <html> <body> <form runat="server"> <h3>FormView Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" emptydatatext="No employees found." onpageindexchanging="EmployeeFormView_OnPageIndexChanging" onmodechanged="EmployeeFormView_OnModeChanged" runat="server"> <rowstyle backcolor="LightGreen" wrap="false"/> <editrowstyle backcolor="LightBlue" wrap="false"/> <itemtemplate> <table> <tr> <td rowspan="4"> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td colspan="2"> </td> </tr> <tr> <td> <b>Name:</b> </td> <td> <%# Eval("FirstName") %> <%# Eval("LastName") %> </td> </tr> <tr> <td> <b>Title:</b> </td> <td> <%# Eval("Title") %> </td> </tr> <tr> <td colspan="2"> <asp:linkbutton id="Edit" text="Edit" commandname="Edit" runat="server"/> </td> </tr> </table> </itemtemplate> <edititemtemplate> <table> <tr> <td rowspan="4"> <asp:image id="EmployeeEditImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td colspan="2"> </td> </tr> <tr> <td> <b>Name:</b> </td> <td> <asp:textbox id="FirstNameUpdateTextBox" text='<%# Bind("FirstName") %>' runat="server"/> <asp:textbox id="LastNameUpdateTextBox" text='<%# Bind("LastName") %>' runat="server"/> </td> </tr> <tr> <td> <b>Title:</b> </td> <td> <asp:textbox id="TitleUpdateTextBox" text='<%# Bind("Title") %>' runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:linkbutton id="UpdateButton" text="Update" commandname="Update" runat="server"/> <asp:linkbutton id="CancelButton" text="Cancel" commandname="Cancel" runat="server"/> </td> </tr> </table> </edititemtemplate> </asp:formview> <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="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]" updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title Where [EmployeeID]=@EmployeeID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FormView クラス
FormView メンバ
System.Web.UI.WebControls 名前空間
FormViewMode
DefaultMode
ChangeMode
ModeChanged
ModeChanging
Weblioに収録されているすべての辞書からFormView.CurrentMode プロパティを検索する場合は、下記のリンクをクリックしてください。

- FormView.CurrentMode プロパティのページへのリンク