ImageField.DataImageUrlFormatString プロパティ

定義

ImageField オブジェクトの各イメージの URL の表示書式を指定する文字列を取得または設定します。

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

プロパティ値

String

ImageField オブジェクトの各イメージの URL の表示書式を指定する文字列。 既定値は空の文字列です ("")。この値は、URL に適用される特定の書式が設定されていないことを示します。

次のコード例は、プロパティを使用して、オブジェクト内の DataImageUrlFormatString イメージの URL 値にカスタム形式を適用する方法を ImageField 示しています。


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

注釈

このプロパティを DataImageUrlFormatString 使用して、オブジェクトに表示されるイメージの URL のカスタム形式を ImageField 指定します。 これは、オブジェクトに単にファイル名が含まれている場合など、URL を生成する必要がある場合 ImageField に便利です。 プロパティが DataImageUrlFormatString 設定されていない場合、URL 値は特別な書式を取得しません。

書式指定文字列には任意のリテラル文字列を指定でき、通常はフィールドの値のプレースホルダーが含まれます。 たとえば、書式指定文字列 "Item Value: {0}", the "{0}" placeholder is replaced with the value of the fields specified by the DataImageUrlField property. 書式指定文字列の残りの部分は、リテラル テキストとして表示されます。

注意

書式指定文字列にプレースホルダーが含まれていない場合、データ ソースのフィールドの値は最終的な表示テキストに含まれません。

プレースホルダーは、コロン (":") で区切られ、中かっこ (""{}) で囲まれた 2 つの部分で構成 {A:Bxx}されます。 コロンの前の値 (A 一般的な例では) は、パラメーターの 0 から始まるリスト内のフィールド値のインデックスを指定します。

注意

このパラメーターは書式設定構文の一部です。 各セルにはフィールド値が 1 つしかないため、この値は 0 にのみ設定できます。

コロンとコロンの後の値は省略可能です。 コロンの後の文字 (B 一般的な例では) は、値を表示する形式を指定します。 次の表に、一般的な形式を示します。

文字の書式設定 説明
C 数値を通貨形式で表示します。
D 数値を 10 進形式で表示します。
E 数値を指数 (指数) 形式で表示します。
F 数値を固定形式で表示します。
G 数値を一般的な形式で表示します。
N 数値を数値形式で表示します。
X 数値を 16 進数形式で表示します。

注意

書式文字は大文字と小文字を区別しません。ただし X、指定した場合は 16 進文字が表示されます。

書式文字の後の値 (一般的な例では xx) は、表示する有効桁数または小数点以下の桁数を指定します。 たとえば、書式指定文字列 "{0:F2}" には、小数点以下 2 桁の固定小数点番号が表示されます。

書式設定の詳細については、「書式設定の 種類」を参照してください

適用対象

こちらもご覧ください