BoundField.ApplyFormatInEditMode 속성

정의

DataFormatString 개체가 들어 있는 데이터 바인딩된 컨트롤이 편집 모드에 있는 경우 BoundField 속성으로 지정된 서식 문자열이 필드 값에 적용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 virtual property bool ApplyFormatInEditMode { bool get(); void set(bool value); };
public virtual bool ApplyFormatInEditMode { get; set; }
member this.ApplyFormatInEditMode : bool with get, set
Public Overridable Property ApplyFormatInEditMode As Boolean

속성 값

Boolean

편집 모드에서 필드 값에 서식 문자열이 적용되면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 ApplyFormatInEditMode 하는 동안 필드 값에 서식을 적용 하려면 속성 문자열을 GridView 컨트롤이 편집 모드 인지 합니다. 서식 지정 후 프로그래밍 방식으로 전에 제거 됩니다 데이터 소스의 값이 업데이트 됩니다.


<%@ 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 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 xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>BoundField Example</title>
</head>
<body>
    <form id="form1" 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>

<%@ Page language="VB" AutoEventWireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>BoundField Example</title>
</head>
<body>
    <form id="form1" 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>

설명

데이터 바인딩된 컨트롤 (같은 DetailsView, FormView, 및 GridView) 다른 디스플레이 모드를 읽기, 편집 또는 레코드를 삽입 하는 데 사용할 수 있습니다. 기본적으로 서식 지정 문자열에서 지정 된 DataFormatString 데이터 바인딩된 컨트롤을 읽기 전용 모드에 있을 때만 속성 필드 값에 적용 됩니다. 서식 문자열에 데이터 바인딩된 컨트롤이 편집 모드에 있는 동안 표시 되는 값을 적용 하려면 설정 합니다 ApplyFormatInEditMode 속성을 true입니다.

참고

BoundField 개체 서식 지정 필드는 데이터 원본에서 업데이트 되 면 자동으로 제거 되지 않습니다. 원하지 않는 저장 된 값의 일부분으로 서식 지정를 사용 하는 경우에 서식을 프로그래밍 방식으로 제거 합니다.

적용 대상

추가 정보