TemplateField.AlternatingItemTemplate プロパティ
アセンブリ: 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TemplateField.AlternatingItemTemplate プロパティのページへのリンク