MenuItemBinding.FormatString Propriedade

Definição

Obtém ou define a cadeia de caracteres que especifica o formato de exibição do texto de um item de menu ao qual o objeto MenuItemBinding é aplicado.Gets or sets the string that specifies the display format for the text of a menu item to which the MenuItemBinding 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

Valor da propriedade

String

Uma cadeia de caracteres de formatação que especifica o formato de exibição para o texto de um item de menu ao qual o MenuItemBinding é aplicado.A formatting string that specifies the display format for the text of a menu item to which the MenuItemBinding is applied. O padrão é uma cadeia de caracteres vazia (""), que indica que essa propriedade não está definida.The default is an empty string (""), which indicates that this property is not set.

Exemplos

O exemplo de código a seguir demonstra como usar a FormatString propriedade para formatar o texto exibido nos itens de menu de um Menu controle.The following code example demonstrates how to use the FormatString property to format the text displayed in the menu items of a Menu control. Para que este exemplo funcione corretamente, você deve copiar os dados XML de exemplo abaixo para um arquivo chamado Menu.xml.For this example to work correctly, you must copy the sample XML data below to a file named Menu.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>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <DataBindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </DataBindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </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>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <DataBindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </DataBindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

O código a seguir é um exemplo de dados de mapa do site para o exemplo anterior.The following code is sample site map data for the previous example.

<MapHomeNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapHomeNode>

Comentários

A FormatString propriedade é usada para fornecer um formato personalizado para o texto de um item de menu.The FormatString property is used to provide a custom format for a menu item's text. A cadeia de caracteres de formato pode consistir em uma cadeia de caracteres literal, um espaço reservado ou ambos.The format string can consist of a literal string, a placeholder, or both. A cadeia de caracteres literal é exibida textualmente, enquanto o espaço reservado é substituído pelo valor associado ao texto do item de menu.The literal string is displayed verbatim, while the placeholder is replaced with the value that is bound to the menu item's text.

O espaço reservado é dividido em duas partes, separadas por dois-pontos, no formato { A : Bxx }.The placeholder is split into two parts, separated by a colon, in the form {A:Bxx}. Por exemplo, {0:F2} exibe um número de ponto fixo com duas casas decimais.For example, {0:F2} displays a fixed-point number with two decimal places.

Observação

A cadeia de caracteres de espaço reservado deve ser colocada entre chaves para indicar que é um espaço reservado e não uma cadeia de caracteres literal.The placeholder string must be enclosed in braces to indicate that it is a placeholder and not a literal string. Qualquer texto fora das chaves é exibido como texto literal.Any text outside the braces is displayed as literal text.

Ao manter a sintaxe de cadeia de caracteres de formatação padrão, o valor antes dos dois-pontos ( A no exemplo geral) especifica o índice de parâmetro em uma lista de parâmetros com base em zero.Keeping to the standard formatting string syntax, the value before the colon (A in the general example) specifies the parameter index in a zero-based list of parameters. Como apenas um valor pode ser exibido em cada item de menu, o índice de parâmetro só pode ser definido como 0.Because only one value can be displayed in each menu item, the parameter index can be set only to 0.

O caractere após os dois-pontos ( B no exemplo geral) especifica o formato de exibição para o valor.The character after the colon (B in the general example) specifies the display format for the value. A tabela a seguir lista os formatos comuns.The following table lists the common formats.

Formatar caractereFormat character DescriçãoDescription
C Exibe valores numéricos no formato de moeda.Displays numeric values in currency format.
D Exibe valores numéricos em formato decimal.Displays numeric values in decimal format.
E Exibe valores numéricos no formato científico (exponencial).Displays numeric values in scientific (exponential) format.
F Exibe valores numéricos no formato fixo.Displays numeric values in fixed format.
G Exibe valores numéricos em formato geral.Displays numeric values in general format.
N Exibe valores numéricos em formato de número.Displays numeric values in number format.
X Exibe valores numéricos em formato hexadecimal.Displays numeric values in hexadecimal format.

Observação

Os caracteres de formato não diferenciam maiúsculas de minúsculas, exceto para X , que exibe os caracteres hexadecimais no caso especificado.The format characters are not case-sensitive, except for X, which displays the hexadecimal characters in the case specified.

O valor após o caractere de formato ( xx no exemplo geral) especifica o número de dígitos significativos ou casas decimais a serem exibidos.The value after the format character (xx in the general example) specifies the number of significant digits or decimal places to display.

Para mais informações sobre cadeias de caracteres de formatação, consulte Tipos de formatação.For more information on formatting strings, see Formatting Types.

O valor dessa propriedade, quando definido, pode ser salvo automaticamente em um arquivo de recurso usando uma ferramenta de designer.The value of this property, when set, can be saved automatically to a resource file by using a designer tool. Para obter mais informações, consulte, LocalizableAttribute globalização e localização.For more information, see LocalizableAttribute and Globalization and Localization.

Aplica-se a

Confira também