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

DetailsViewMode 値の 1 つ。

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

CurrentMode プロパティを使用して、DetailsView コントロールが編集、挿入、または読み取り専用のいずれのモードであるかを確認する方法のコード例を次に示します。DetailsView コントロールが編集モードの場合にユーザーが別のレコードに移動しようとすると、ページング操作はキャンセルされます。
<%@ Page Language="VB" %> <script runat="server"> Sub CustomerDetailView_ItemCommand(ByVal sender As Object, _ ByVal e As DetailsViewCommandEventArgs) ' Clear the error message if the user cancels the edit ' operation. If e.CommandName = "Cancel" Then ErrorMessageLabel.Text = "" End If End Sub Protected Sub CustomerDetailView_PageIndexChanging( _ ByVal sender As Object, ByVal e As DetailsViewPageEventArgs) ' Cancel the paging operation if the user tries to navigate ' to another record while in edit mode. If CustomerDetailView.CurrentMode = DetailsViewMode.Edit Then e.Cancel = True ' Display an error message. ErrorMessageLabel.Text = _ "You cannot navigate to another record while in edit mode." End If End Sub </script> <html> <body> <form id="Form1" runat="server"> <h3> DetailsView CurrentMode Example</h3> <asp:DetailsView ID="CustomerDetailView" DataSourceID="DetailsViewSource" AutoGenerateRows="true" AutoGenerateEditButton="true" DataKeyNames="CustomerID" GridLines="Both" AllowPaging="true" OnItemCommand="CustomerDetailView_ItemCommand" runat="server" OnPageIndexChanging="CustomerDetailView_PageIndexChanging"> <HeaderStyle BackColor="Navy" ForeColor="White" /> </asp:DetailsView> <br /> <asp:Label ID="ErrorMessageLabel" 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" 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="C#" %> <script runat="server"> void CustomerDetailView_ItemCommand(Object sender, DetailsViewCommandEventArgs e) { // Clear the error message if the user cancels the edit // operation. if (e.CommandName == "Cancel") { ErrorMessageLabel.Text = ""; } } protected void CustomerDetailView_PageIndexChanging( object sender, DetailsViewPageEventArgs e) { // Cancel the paging operation if the user tries to // navigate to another record while in edit mode. if (CustomerDetailView.CurrentMode == DetailsViewMode.Edit) { e.Cancel = true; // Display an error message. ErrorMessageLabel.Text = "You cannot navigate to another record while in edit mode."; } } </script> <html> <body> <form id="Form1" runat="server"> <h3> DetailsView CurrentMode Example</h3> <asp:DetailsView ID="CustomerDetailView" DataSourceID="DetailsViewSource" AutoGenerateRows="true" AutoGenerateEditButton="true" DataKeyNames="CustomerID" GridLines="Both" AllowPaging="true" OnItemCommand="CustomerDetailView_ItemCommand" runat="server" OnPageIndexChanging="CustomerDetailView_PageIndexChanging"> <HeaderStyle BackColor="Navy" ForeColor="White" /> </asp:DetailsView> <br /> <asp:Label ID="ErrorMessageLabel" 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" 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>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDetailsView.CurrentMode プロパティを検索する場合は、下記のリンクをクリックしてください。

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