다음을 통해 공유


HyperLinkField.DataTextFormatString 속성

정의

개체의 하이퍼링크 캡션이 표시되는 형식을 지정하는 문자열을 HyperLinkField 얻거나 설정합니다.

public:
 virtual property System::String ^ DataTextFormatString { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataTextFormatString { get; set; }
member this.DataTextFormatString : string with get, set
Public Overridable Property DataTextFormatString As String

속성 값

하이퍼링크 캡션이 표시되는 형식을 지정하는 HyperLinkField 문자열입니다. 기본값은 하이퍼링크 캡션에 특수 서식이 적용되지 않음을 나타내는 빈 문자열("")입니다.

예제

다음 코드 예제에서는 개체에 DataTextFormatString 표시 HyperLinkField 되는 하이퍼링크 캡션에 바인딩된 값의 형식을 속성을 사용 하는 방법을 보여 줍니다. 값은 통화 형식으로 지정됩니다.


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>HyperLinkField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- The UnitPrice field values are bound to the         -->
      <!-- captions of the hyperlinks in the HyperLinkField    -->
      <!-- field column, formatted as currency. The ProductID  -->
      <!-- field values are bound to the navigate URLs of the  -->
      <!-- hyperlinks. However, instead of being the actual    -->
      <!-- URL values, the product ID is passed to the linked  -->
      <!-- page as a parameter in the URL specified by the     -->
      <!-- DataNavigateUrlFormatString property.               -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="Order ID"/>
          <asp:boundfield datafield="ProductID" 
            headertext="Product ID"/>
          <asp:hyperlinkfield datatextfield="UnitPrice"
            datatextformatstring="{0:c}"
            datanavigateurlfields="ProductID"
            datanavigateurlformatstring="~\details.aspx?ProductID={0}"          
            headertext="Price"
            target="_blank" />
          <asp:boundfield datafield="Quantity" 
            headertext="Quantity"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>HyperLinkField DataTextFormatString and DataNavigateUrlFormatString Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField DataTextFormatString and DataNavigateUrlFormatString Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- The UnitPrice field values are bound to the         -->
      <!-- captions of the hyperlinks in the HyperLinkField    -->
      <!-- field column, formatted as currency. The ProductID  -->
      <!-- field values are bound to the navigate URLs of the  -->
      <!-- hyperlinks. However, instead of being the actual    -->
      <!-- URL values, the product ID is passed to the linked  -->
      <!-- page as a parameter in the URL specified by the     -->
      <!-- DataNavigateUrlFormatString property.               -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="Order ID"/>
          <asp:boundfield datafield="ProductID" 
            headertext="Product ID"/>
          <asp:hyperlinkfield datatextfield="UnitPrice"
            datatextformatstring="{0:c}"
            datanavigateurlfields="ProductID"
            datanavigateurlformatstring="~\details.aspx?ProductID={0}"          
            headertext="Price"
            target="_blank" />
          <asp:boundfield datafield="Quantity" 
            headertext="Quantity"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

설명

개체에 DataTextFormatString 표시되는 HyperLinkField 캡션에 대한 사용자 지정 표시 형식을 지정하려면 이 속성을 사용합니다. DataTextFormatString 속성을 설정하지 않으면 특수 서식 없이 필드 값이 표시됩니다.

메모

형식 문자열은 속성이 DataTextField 설정된 경우에만 적용됩니다.

형식 문자열은 모든 리터럴 문자열일 수 있으며 일반적으로 필드 값에 대한 자리 표시자를 포함합니다. 예를 들어 "Item Value: {0}" {0} 형식 문자열에서 개체 틀은 개체에 표시 HyperLinkField 될 때 필드 값으로 바뀝니다. 나머지 서식 문자열은 리터럴 텍스트로 표시됩니다.

메모

서식 문자열에 자리 표시자가 포함되어 있지 않으면 데이터 원본의 필드 값이 최종 표시 텍스트에 포함되지 않습니다.

자리 표시자는 콜론으로 구분되고 중괄호로 래핑된 두 부분으로 {A:Bxx}형식으로 구성됩니다. 콜론 앞의 값(A 일반적인 예에서)은 매개 변수의 0부터 시작하는 목록에서 필드 값의 인덱스를 지정합니다.

메모

이 매개 변수는 서식 구문의 일부입니다. 각 셀에는 필드 값이 하나뿐이므로 이 값은 0으로만 설정할 수 있습니다.

콜론과 콜론 뒤의 값은 선택 사항입니다. 콜론 뒤의 문자(B 일반적인 예에서)는 값을 표시할 형식을 지정합니다. 다음 표에서는 일반적인 형식을 나열합니다.

문자 서식 지정 설명
C 숫자 값을 통화 형식으로 표시합니다.
D 숫자 값을 10진수 형식으로 표시합니다.
E 숫자 값을 과학적(지수) 형식으로 표시합니다.
F 숫자 값을 고정 형식으로 표시합니다.
G 숫자 값을 일반 형식으로 표시합니다.
N 숫자 값을 숫자 형식으로 표시합니다.
X 숫자 값을 16진수 형식으로 표시합니다.

메모

형식 문자는 대/소문자를 구분하지 않습니다. 단 X, 지정된 경우 16진수 문자를 표시합니다.

서식 문자 뒤의 값(xx 일반적인 예에서)은 표시할 유효 자릿수 또는 소수 자릿수를 지정합니다. 예를 들어 형식 문자열 "{0:F2}"은 소수점이 두 자리인 고정 소수점 숫자를 표시합니다.

문자열 서식 지정에 대한 자세한 내용은 형식 서식 지정을 참조하세요.

적용 대상

추가 정보