TemplateField.AlternatingItemTemplate プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TemplateField.AlternatingItemTemplate プロパティの意味・解説 

TemplateField.AlternatingItemTemplate プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

TemplateField オブジェクトの交互の項目を表示するときに使用するテンプレートを取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<TemplateContainerAttribute(GetType(IDataItemContainer), BindingDirection.TwoWay)>
 _
Public Overridable Property
 AlternatingItemTemplate As ITemplate
Dim instance As TemplateField
Dim value As ITemplate

value = instance.AlternatingItemTemplate

instance.AlternatingItemTemplate = value
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)]
 
public virtual ITemplate AlternatingItemTemplate { get;
 set; }
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection::TwoWay)]
 
public:
virtual property ITemplate^ AlternatingItemTemplate {
    ITemplate^ get ();
    void set (ITemplate^ value);
}
/** @property */
public ITemplate get_AlternatingItemTemplate ()

/** @property */
public void set_AlternatingItemTemplate (ITemplate
 value)
public function get AlternatingItemTemplate
 () : ITemplate

public function set AlternatingItemTemplate
 (value : ITemplate)

プロパティ値
TemplateField の交互の項目を表示するときに使用するテンプレートを格納している System.Web.UI.ITemplate 実装オブジェクト。既定値は null 参照 (Visual Basic では Nothing) です。このプロパティが設定されていないことを示します。

解説解説

AlternatingItemTemplate プロパティを使用して、TemplateField オブジェクトの交互の項目に表示するカスタムの内容を指定します。交互の項目を表示する方法を指定するテンプレートを作成して、内容を定義します。

メモメモ

AlternatingItemTemplate プロパティは、通常、データ バインド コントロールの項目を 1 つおきに異なる外観に設定する場合に ItemTemplate プロパティと組み合わせて使用します。

テンプレートを指定するには、まず、<TemplateField> 要素の開始タグと終了タグの間に <AlternatingItemTemplate> の開始タグと終了タグを配置します。次に、開始 <AlternatingItemTemplate> タグと終了 <AlternatingItemTemplate> タグの間にカスタムの内容を追加します。内容は、簡単なプレーンテキストとしたり、テンプレートに他のコントロールを埋め込んで複雑にしたりできます。

テンプレートで定義されたコントロールにプログラムからアクセスするには、まず、そのコントロールが、データ バインド コントロールの、どの TableCell オブジェクトに含まれるかを確認します。次に、TableCell オブジェクトの Controls コレクションを使用してコントロールにアクセスします。コントロールに ID プロパティが指定されている場合は、TableCell オブジェクトの FindControl メソッドを使用してコントロールを検索することもできます。

使用例使用例

AlternatingItemTemplate プロパティを使用して、GridView コントロールの TemplateField フィールド列に表示される交互の項目のカスタム テンプレートを作成するコード例を次に示します。このテンプレートは、指定した ItemTemplate プロパティのテンプレートの一種です。このテンプレートでは、イメージがセルの反対側に表示されます。

<%@ Page language="VB" %>

<html>
  <body>
    <form runat="server">
        
      <h3>TemplateField AlternatingItemTemplate Example</h3>

      <!-- Populate the Columns collection declaratively.    -->
      <!-- Create a TemplateField field column that has both      -->
      <!-- an  item template and an alternating item template.
    -->
      <!-- The item template displays an author's image on the  
  -->
      <!-- left side of the column, while
 the alternating item    -->
      <!-- template displays an author's image on the right side.
 -->
      
      <!-- For this example, the zip field is
 used for the        -->
      <!-- values of the image URL. For
 your application, you     -->
      <!-- should use a field that contains valid URLs to 
        -->
      <!-- images.                                                -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
                
          <asp:templatefield headertext="Author">
            <itemtemplate>
              <asp:image id="LeftAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"  
                runat="server"/>
              <asp:label id="LeftFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="LeftLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
            </itemtemplate>
            <alternatingitemtemplate>
              <asp:label id="RightFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="RightLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
              <asp:image id="RightAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"
                runat="server"/>
            </alternatingitemtemplate>
          </asp:templatefield>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Pubs sample database.                   
     -->
      <asp:sqldatasource id="AuthorsSqlDataSource"
  
        selectcommand="SELECT [au_lname], [au_fname], [zip] FROM
 [authors]"
        connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<html>
  <body>
    <form runat="server">
        
      <h3>TemplateField AlternatingItemTemplate Example</h3>

      <!-- Populate the Columns collection declaratively.    -->
      <!-- Create a TemplateField field column that has both      -->
      <!-- an  item template and an alternating item template.    -->
      <!-- The item template displays an author's image on the    -->
      <!-- left side of the column, while the alternating item
    -->
      <!-- template displays an author's image on the right side. -->
      
      <!-- For this example, the zip field is used for
 the        -->
      <!-- values of the image URL. For your application, you     -->
      <!-- should use a field that contains valid URLs to         -->
      <!-- images.                                                -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
                
          <asp:templatefield headertext="Author">
            <itemtemplate>
              <asp:image id="LeftAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"  
                runat="server"/>
              <asp:label id="LeftFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="LeftLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
            </itemtemplate>
            <alternatingitemtemplate>
              <asp:label id="RightFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="RightLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
              <asp:image id="RightAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"
                runat="server"/>
            </alternatingitemtemplate>
          </asp:templatefield>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname], [zip] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TemplateField クラス
TemplateField メンバ
System.Web.UI.WebControls 名前空間
EditItemTemplate
FooterTemplate
HeaderTemplate
InsertItemTemplate
ItemTemplate



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「TemplateField.AlternatingItemTemplate プロパティ」の関連用語

TemplateField.AlternatingItemTemplate プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TemplateField.AlternatingItemTemplate プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS