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

Dim instance As BoundField Dim value As Boolean value = instance.ApplyFormatInEditMode instance.ApplyFormatInEditMode = value
/** @property */ public boolean get_ApplyFormatInEditMode () /** @property */ public void set_ApplyFormatInEditMode (boolean value)
public function get ApplyFormatInEditMode () : boolean public function set ApplyFormatInEditMode (value : boolean)
編集モードで書式指定文字列をフィールド値に適用する場合は true。それ以外の場合は false。既定値は false です。

データ バインド コントロール (DetailsView、FormView、GridView など) には、ユーザーがレコードの読み取り、編集、または挿入を行うための各種の表示モードがあります。既定では、データ バインド コントロールが読み取り専用モードの場合だけ、DataFormatString プロパティで指定された書式指定文字列がフィールド値に適用されます。データ バインド コントロールが編集モードの場合に書式指定文字列を表示値に適用するには、ApplyFormatInEditMode プロパティを true に設定します。
![]() |
---|
データ ソースのフィールドが更新された場合に、BoundField オブジェクトは書式指定を自動的に削除しません。書式指定を格納した値の一部として処理しない場合は、この書式指定をプログラムで削除する必要があります。 |

ApplyFormatInEditMode プロパティを使用して、GridView コントロールが編集モードである場合にフィールド値に書式指定文字列を適用するコード例を次に示します。値がデータ ソースで更新される前に、書式指定がプログラムで削除されます。
<%@ Page language="VB" AutoEventWireup="false" %> <script runat="server"> Sub CustomersGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles CustomersGridView.RowUpdating ' Use the NewValues property to retrieve the updated CustomerID ' value entered by the user. Dim customerID As String = e.NewValues("CustomerID").ToString() ' Remove the formating applied by the DataFormatString property. If customerID.StartsWith("D:") Then e.NewValues("CustomerID") = customerID.Substring(2) End If End Sub </script> <html> <body> <form runat="server"> <h3>BoundField Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" runat="server"> <columns> <asp:boundfield datafield="CustomerID" dataformatstring="D:{0}" applyformatineditmode="true" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" convertemptystringtonull="true" headertext="Customer Name"/> <asp:boundfield datafield="Address" convertemptystringtonull="true" headertext="Address"/> <asp:boundfield datafield="City" convertemptystringtonull="true" headertext="City"/> <asp:boundfield datafield="PostalCode" convertemptystringtonull="true" headertext="ZIP Code"/> <asp:boundfield datafield="Country" convertemptystringtonull="true" headertext="Country"/> </columns> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" updatecommand="Update Customers Set CustomerID=@CustomerID, CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e) { // Use the NewValues property to retrieve the updated CustomerID // value entered by the user. String customerID = e.NewValues["CustomerID"].ToString(); // Remove the formating applied by the DataFormatString property. if(customerID.StartsWith("D:")) { e.NewValues["CustomerID"] = customerID.Substring(2); } } </script> <html> <body> <form runat="server"> <h3>BoundField Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" onrowupdating="CustomersGridView_RowUpdating" runat="server"> <columns> <asp:boundfield datafield="CustomerID" dataformatstring="D:{0}" applyformatineditmode="true" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" convertemptystringtonull="true" headertext="Customer Name"/> <asp:boundfield datafield="Address" convertemptystringtonull="true" headertext="Address"/> <asp:boundfield datafield="City" convertemptystringtonull="true" headertext="City"/> <asp:boundfield datafield="PostalCode" convertemptystringtonull="true" headertext="ZIP Code"/> <asp:boundfield datafield="Country" convertemptystringtonull="true" headertext="Country"/> </columns> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" updatecommand="Update Customers Set CustomerID=@CustomerID, CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </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に収録されているすべての辞書からBoundField.ApplyFormatInEditMode プロパティを検索する場合は、下記のリンクをクリックしてください。

- BoundField.ApplyFormatInEditMode プロパティのページへのリンク