HyperLinkField.DataNavigateUrlFormatString プロパティ

定義

HyperLinkField オブジェクトに表示されるハイパーリンクの URL に対して書式を指定する文字列を取得または設定します。

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

プロパティ値

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

次のコード例では、 プロパティを DataNavigateUrlFormatString 使用して、オブジェクトに表示されるハイパーリンクのナビゲーション URL に適用するカスタム形式を指定する方法を HyperLinkField 示します。 プロパティで DataTextField 指定されたフィールドの値は、書式指定文字列で指定された Web ページにクエリ文字列として渡されます。


<%@ 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>HyperLinkField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- The UnitPrice field values are bound to the         -->
      <!-- captions of the hyperlinks in the HyperLinkField    -->
      <!-- field column, formatted as currency. The ProductID  -->
      <!-- field values are bound to the navigate URLs of the  -->
      <!-- hyperlinks. However, instead of being the actual    -->
      <!-- URL values, the product ID is passed to the linked  -->
      <!-- page as a parameter in the URL specified by the     -->
      <!-- DataNavigateUrlFormatString property.               -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="Order ID"/>
          <asp:boundfield datafield="ProductID" 
            headertext="Product ID"/>
          <asp:hyperlinkfield datatextfield="UnitPrice"
            datatextformatstring="{0:c}"
            datanavigateurlfields="ProductID"
            datanavigateurlformatstring="~\details.aspx?ProductID={0}"          
            headertext="Price"
            target="_blank" />
          <asp:boundfield datafield="Quantity" 
            headertext="Quantity"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </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>HyperLinkField DataTextFormatString and DataNavigateUrlFormatString Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField DataTextFormatString and DataNavigateUrlFormatString Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- The UnitPrice field values are bound to the         -->
      <!-- captions of the hyperlinks in the HyperLinkField    -->
      <!-- field column, formatted as currency. The ProductID  -->
      <!-- field values are bound to the navigate URLs of the  -->
      <!-- hyperlinks. However, instead of being the actual    -->
      <!-- URL values, the product ID is passed to the linked  -->
      <!-- page as a parameter in the URL specified by the     -->
      <!-- DataNavigateUrlFormatString property.               -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="Order ID"/>
          <asp:boundfield datafield="ProductID" 
            headertext="Product ID"/>
          <asp:hyperlinkfield datatextfield="UnitPrice"
            datatextformatstring="{0:c}"
            datanavigateurlfields="ProductID"
            datanavigateurlformatstring="~\details.aspx?ProductID={0}"          
            headertext="Price"
            target="_blank" />
          <asp:boundfield datafield="Quantity" 
            headertext="Quantity"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

注釈

プロパティを DataNavigateUrlFormatString 使用して、オブジェクト内のハイパーリンクの URL のカスタム形式を HyperLinkField 指定します。 プロパティが DataNavigateUrlFormatString 設定されていない場合、ハイパーリンクの URL は特別な書式を取得しません。

注意

書式指定文字列は、 プロパティが DataNavigateUrlFields 設定されている場合にのみ適用されます。

書式指定文字列には任意のリテラル文字列を指定でき、通常はフィールドの値のプレースホルダーが含まれます。 たとえば、書式指定文字列 "Item Value: {0}"では、 {0} プレースホルダーは オブジェクト内のフィールドの値に HyperLinkField 置き換えられます。 書式指定文字列の残りの部分はリテラル テキストとして表示されます。

注意

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

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

注意

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

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

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

注意

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

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

書式指定文字列の詳細については、「Formatting Types」(型の書式設定) を参照してください。

適用対象

こちらもご覧ください