Editare

Partajați prin


TreeNodeBinding.FormatString Property

Definition

Gets or sets the string that specifies the display format for the text of a node to which the TreeNodeBinding object is applied.

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

Property Value

A formatting string that specifies the display format for the text of a node to which the TreeNodeBinding object is applied. The default is an empty string (""), which indicates that the FormatString property is not set.

Examples

This section contains two code examples. The first code example demonstrates how to use the FormatString property to specify a custom display format for the text that is displayed in the root node. The second code example provides sample XML data for the first code example.

The following code example demonstrates how to use the FormatString property to specify a custom display format for the text that is displayed in the root node. For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named 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>

The following code example is sample XML data for the preceding example.

<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>  

Remarks

The FormatString property is used to provide a custom format for a node's text. The data format string consists of two parts, separated by a colon, in the form { A : Bxx }. For example, the formatting string {0:F2} displays a fixed-point number with two decimal places.

Note

The entire string must be enclosed in braces to indicate that it is a format string and not a literal string. Any text outside the braces is displayed as literal text.

The value before the colon (A in the general example) specifies the parameter index in a zero-based list of parameters.

Note

This value can be set only to 0 because there is only one value in each node.

The character after the colon (B in the general example) specifies the display format for the value. The following table lists the common formats.

Format character Displays numeric values in
C Currency format.
D Decimal format.
E Scientific (exponential) format.
F Fixed format.
G General format.
N Number format.
X Hexadecimal format.

Note

Except for X, the format character is not case sensitive. The X format character displays the hexadecimal characters in the case that is specified.

The value after the format character (xx in the general example) specifies the number of significant digits or decimal places to display.

For more information on formatting strings, see Formatting Types.

The value of this property is stored in view state.

The value of the FormatString property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and Globalization and Localization.

Applies to

See also