Export (0) Print
Expand All

TreeNodeBinding.FormatString Property

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

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public string FormatString { get; set; }

Property Value

Type: System.String
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.

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.

NoteNote:

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.

NoteNote:

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.

NoteNote:

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

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 ASP.NET Globalization and Localization.

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>

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>

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft