TreeNodeBinding.FormatString プロパティ

定義

TreeNodeBinding オブジェクトが適用されるノードのテキストの表示形式を指定する文字列を取得または設定します。

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

プロパティ値

TreeNodeBinding オブジェクトが適用されるノードのテキストの表示形式を指定する書式指定文字列。 既定値は空の文字列 ("") です。FormatString プロパティが設定されていないことを示します。

このセクションには、2 つのコード例が含まれています。 最初のコード例では、 プロパティを FormatString 使用して、ルート ノードに表示されるテキストのカスタム表示形式を指定する方法を示します。 2 番目のコード例では、最初のコード例のサンプル XML データを提供します。

次のコード例では、 プロパティを FormatString 使用して、ルート ノードに表示されるテキストのカスタム表示形式を指定する方法を示します。 この例を正しく機能させるには、このコード例の後に提供されるサンプル XML データを Book.xml という名前のファイルにコピーする必要があります。


<%@ 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>TreeNodeBinding FormatString Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBinding FormatString Example</h3>
    
      <!-- Use the FormatString property to apply   -->
      <!-- a custom format string to the root node. -->
      <!-- The placeholder ({0}) is automatically   -->
      <!-- replaced with the value of the field     -->
      <!-- specified in the TextField property.     -->
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            Depth="0"
            TextField="Title" 
            FormatString="Best Seller: {0}"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            Depth="1" 
            TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Appendix" 
            Depth="1" 
            TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
    </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>TreeNodeBinding FormatString Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBinding FormatString Example</h3>
    
      <!-- Use the FormatString property to apply   -->
      <!-- a custom format string to the root node. -->
      <!-- The placeholder ({0}) is automatically   -->
      <!-- replaced with the value of the field     -->
      <!-- specified in the TextField property.     --> 
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         runat="server">
          
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            Depth="0"
            TextField="Title" 
            FormatString="Best Seller: {0}"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            Depth="1" 
            TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Appendix" 
            Depth="1" 
            TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

次のコード例は、前の例のサンプル XML データです。

<Book Title="Book Title">  
    <Chapter Heading="Chapter 1">  
        <Section Heading="Section 1">  
        </Section>  
        <Section Heading="Section 2">  
        </Section>  
    </Chapter>  
    <Chapter Heading="Chapter 2">  
        <Section Heading="Section 1">  
        </Section>  
    </Chapter>  
    <Appendix Heading="Appendix A">  
    </Appendix>  
</Book>  

注釈

プロパティは FormatString 、ノードのテキストのカスタム形式を提供するために使用されます。 データ書式指定文字列は、コロンで区切られた 2 つの部分で構成されます({ A : Bxx })。 たとえば、書式設定文字列 {0:F2} には、小数点以下 2 桁の固定小数点番号が表示されます。

Note

リテラル文字列ではなく書式指定文字列であることを示すには、文字列全体を中かっこで囲む必要があります。 中かっこの外側のすべてのテキストは、リテラル テキストとして表示されます。

コロン (A 一般的な例では) の前の値は、パラメーターの 0 から始まるリスト内のパラメーター インデックスを指定します。

Note

この値は、各ノードに 1 つの値しかないため、0 にのみ設定できます。

コロンの後の文字 (B 一般的な例では) は、値の表示形式を指定します。 次の表に、一般的な形式を示します。

文字の書式設定 に数値を表示します。
C 通貨形式。
D 10 進形式。
E 指数 (指数) 形式。
F 固定形式。
G 一般的な形式。
N 数値の形式。
X 16 進形式。

Note

X除き、書式文字では大文字と小文字は区別されません。 書式文字には X 、指定した場合の 16 進文字が表示されます。

書式文字 (xx の一般的な例では) の後の値は、表示する有効桁数または小数点以下の桁数を指定します。

書式指定文字列の詳細については、「Formatting Types」(型の書式設定) を参照してください。

このプロパティの値はビュー ステートに格納されます。

プロパティの値を FormatString 設定すると、デザイナー ツールを使用してリソース ファイルに自動的に保存できます。 詳細については、「グローバリゼーションとローカライズ」を参照してくださいLocalizableAttribute

適用対象

こちらもご覧ください