Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

BoundField.ApplyFormatInEditMode Property

Gets or sets a value indicating whether the formatting string specified by the DataFormatString property is applied to field values when the data-bound control that contains the BoundField object is in edit mode.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
public virtual bool ApplyFormatInEditMode { get; set; }

Property Value

Type: System.Boolean
true to apply the formatting string to field values in edit mode; otherwise, false. The default is false.

Data-bound controls (such as DetailsView, FormView, and GridView) have different display modes that allow the user to read, edit, or insert records. By default, the formatting string specified by the DataFormatString property is applied to field values only when the data-bound control is in read-only mode. To apply the formatting string to values displayed while the data-bound control is in edit mode, set the ApplyFormatInEditMode property to true.


A BoundField object does not automatically remove the formatting when the field is updated in the data source. If you do not want the formatting as part of the value stored, you will need to remove the formatting programmatically.

The following code example demonstrates how to use the ApplyFormatInEditMode property to apply the formatting string to field values while a GridView control is in edit mode. The formatting is then programmatically removed before the value is updated in the data source.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<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.
      e.NewValues["CustomerID"] = customerID.Substring(2);



<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>BoundField Example</title>
    <form id="form1" runat="server">

      <h3>BoundField Example</h3>

      <asp:gridview id="CustomersGridView" 

          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Customer Name"/>
          <asp:boundfield datafield="Address"
          <asp:boundfield datafield="City"
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"


      <!-- 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%>"


.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.