ImageField.DataImageUrlFormatString Propriedade
Definição
Obtém ou define a cadeia de caracteres que especifica o formato no qual a URL de cada imagem em um objeto ImageField é renderizada.Gets or sets the string that specifies the format in which the URL for each image in an ImageField object is rendered.
public:
virtual property System::String ^ DataImageUrlFormatString { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataImageUrlFormatString { get; set; }
member this.DataImageUrlFormatString : string with get, set
Public Overridable Property DataImageUrlFormatString As String
Valor da propriedade
Uma cadeia de caracteres que especifica o formato no qual a URL de cada imagem em um objeto ImageField é renderizada.A string that specifies the format in which the URL for each image in an ImageField object is rendered. O padrão é a cadeia de caracteres vazia (""), o que indica que nenhuma formatação especial é aplicada às URLs.The default is the empty string ("") , which indicates that no special formatting is applied to the URLs.
Exemplos
O código de exemplo a seguir demonstra como usar a DataImageUrlFormatString propriedade para aplicar um formato personalizado aos valores de URL para as imagens em um ImageField objeto.The following example code demonstrates how to use the DataImageUrlFormatString property to apply a custom format to the URL 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="LastName"
dataimageurlformatstring="~\Images\{0}.jpg"
alternatetext="Employee Photo"
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] 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="LastName"
dataimageurlformatstring="~\Images\{0}.jpg"
alternatetext="Employee Photo"
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] From [Employees]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
Comentários
Use a DataImageUrlFormatString propriedade para especificar um formato personalizado para as URLs das imagens exibidas em um ImageField objeto.Use the DataImageUrlFormatString property to specify a custom format for the URLs of the images displayed in an ImageField object. Isso é útil quando você precisa gerar uma URL, como quando o ImageField objeto simplesmente contém o nome do arquivo.This is useful when you need to generate a URL, such as when the ImageField object simply contains the file name. Se a DataImageUrlFormatString propriedade não for definida, os valores de URL não terão nenhuma formatação especial.If the DataImageUrlFormatString property is not set, the URL values do not get any special formatting.
A cadeia de caracteres de formato pode ser qualquer cadeia de caracteres literal e geralmente contém um espaço reservado para o valor do campo.The format string can be any literal string and usually contains a placeholder for the field's value. Por exemplo, na cadeia de caracteres de formato "valor {0} do item:", o {0} espaço reservado "" é substituído pelo valor dos campos especificados pela DataImageUrlField propriedade.For example, in the format string "Item Value: {0}", the "{0}" placeholder is replaced with the value of the fields specified by the DataImageUrlField property. O restante da cadeia de caracteres de formato é exibido como texto literal.The rest of the format string is displayed as literal text.
Observação
Se a cadeia de caracteres de formato não incluir um espaço reservado, o valor do campo da fonte de dados não será incluído no texto final de exibição.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.
O espaço reservado consiste em duas partes separadas por dois-pontos (":") e encapsulado entre chaves (" {} "), no formato {A:Bxx} .The placeholder consists of two parts separated by a colon (":") and wrapped in braces ("{}"), in the form {A:Bxx}. O valor antes dos dois-pontos ( A no exemplo geral) especifica o índice do valor do campo em uma lista de parâmetros com base em zero.The value before the colon (A in the general example) specifies the field value's index in a zero-based list of parameters.
Observação
Esse parâmetro faz parte da sintaxe de formatação.This parameter is part of the formatting syntax. Como há apenas um valor de campo em cada célula, esse valor só pode ser definido como 0.Because there is only one field value in each cell, this value can only be set to 0.
Os dois-pontos e os valores após os dois-pontos são opcionais.The colon and the values after the colon are optional. O caractere após os dois-pontos ( B no exemplo geral) especifica o formato no qual exibir o valor.The character after the colon (B in the general example) specifies the format in which to display 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. Por exemplo, a cadeia de caracteres de formato " {0:F2} " exibe um número de ponto fixo com 2 casas decimais.For example, the format string "{0:F2}" displays a fixed-point number with 2 decimal places.
Para obter mais informações sobre formatação, consulte tipos de formatação.For more information on formatting, see Formatting Types.