Uredi

Deli z drugimi prek


ImageField.DataAlternateTextFormatString Property

Definition

Gets or sets the string that specifies the format in which the alternate text for each image in an ImageField object is rendered.

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

Property Value

A string that specifies the format in which the alternate text for each image in an ImageField object is rendered. The default is an empty string (""), which indicates that now special formatting is applied to the alternate text.

Examples

The following code example demonstrates how to use the DataAlternateTextFormatString property to apply a custom format to the alternate text values for the images in an ImageField object.


<%@ 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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            dataalternatetextfield="LastName"
            dataalternatetextformatstring="Photo: {0}" 
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </asp:gridview>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            dataalternatetextfield="LastName"
            dataalternatetextformatstring="Photo: {0}" 
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </asp:gridview>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

Remarks

Use the DataAlternateTextFormatString property to specify a custom format for the alternate text values of the images displayed in an ImageField object.

Note

The format string is applied only when the DataAlternateTextField property is set. It is not applied when the AlternateText property is set.

This is useful when you need to modify the original value contained in the field. If the DataAlternateTextFormatString property is not set, the alternate text values do not get any special formatting.

The format string can be any literal string and usually contains a placeholder for the field's value. For example, in the format string "Item Value: {0}", the "{0}" placeholder is replaced with the value of the fields specified by the DataAlternateTextField property. The rest of the format string is displayed as literal text.

Note

If the format string does not include a placeholder, the field's value from the data source is not included in the final display text.

The placeholder consists of two parts separated by a colon (":") and wrapped in braces ("{}"), in the form {A:Bxx}. The value before the colon (A in the general example) specifies the field value's index in a zero-based list of parameters.

Note

This parameter is part of the formatting syntax. Because there is only one field value in each cell, this value can only be set to 0.

The colon and the values after the colon are optional. The character after the colon (B in the general example) specifies the format in which to display the value. The following table lists the common formats.

Format character Description
C Displays numeric values in currency format.
D Displays numeric values in decimal format.
E Displays numeric values in scientific (exponential) format.
F Displays numeric values in fixed format.
G Displays numeric values in general format.
N Displays numeric values in number format.
X Displays numeric values in hexadecimal format.

Note

The format characters are not case sensitive, except for X, which displays the hexadecimal characters in the case specified.

The value after the format character (xx in the general example) specifies the number of significant digits or decimal places to display. For example, the format string "{0:F2}" displays a fixed-point number with 2 decimal places.

For more information on formatting, see Formatting Types.

Applies to

See also