TemplateField.HeaderTemplate プロパティ
アセンブリ: System.Web (system.web.dll 内)

<TemplateContainerAttribute(GetType(IDataItemContainer))> _ Public Overridable Property HeaderTemplate As ITemplate
Dim instance As TemplateField Dim value As ITemplate value = instance.HeaderTemplate instance.HeaderTemplate = value
[TemplateContainerAttribute(typeof(IDataItemContainer))] public virtual ITemplate HeaderTemplate { get; set; }
[TemplateContainerAttribute(typeof(IDataItemContainer))] public: virtual property ITemplate^ HeaderTemplate { ITemplate^ get (); void set (ITemplate^ value); }
/** @property */ public ITemplate get_HeaderTemplate () /** @property */ public void set_HeaderTemplate (ITemplate value)
public function get HeaderTemplate () : ITemplate public function set HeaderTemplate (value : ITemplate)
データ バインド コントロールの TemplateField のヘッダー セクションを表示するときに使用するテンプレートを格納している System.Web.UI.ITemplate 実装オブジェクト。既定値は null 参照 (Visual Basic では Nothing) です。このプロパティが設定されていないことを示します。

HeaderTemplate プロパティを使用して、TemplateField オブジェクトのヘッダー セクションに表示するカスタムの内容を指定します。ヘッダー セクションを表示する方法を指定するテンプレートを作成して、内容を定義します。
テンプレートを指定するには、まず、<TemplateField> 要素の開始タグと終了タグの間に <HeaderTemplate> の開始タグと終了タグを配置します。次に、開始 <HeaderTemplate> タグと終了 <HeaderTemplate> タグの間にカスタムの内容を追加します。内容は、簡単なプレーンテキストとしたり、テンプレートに他のコントロールを埋め込んで複雑にしたりできます。
テンプレートで定義されたコントロールにプログラムからアクセスするには、まず、そのコントロールが、データ バインド コントロールの、どの TableCell オブジェクトに含まれるかを確認します。次に、TableCell オブジェクトの Controls コレクションを使用してコントロールにアクセスします。コントロールに ID プロパティが指定されている場合は、TableCell オブジェクトの FindControl メソッドを使用してコントロールを検索することもできます。

HeaderTemplate プロパティを使用して、GridView コントロールの TemplateField フィールド列に表示されるヘッダー セクションのカスタム テンプレートを作成するコード例を次に示します。このテンプレートは、ユーザーが GridView コントロールの行の表示または非表示を選択できるチェック ボックスを表示します。
<%@ Page language="VB" %> <script runat="server"> Sub SelectAllCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) ' Get the CheckBox control that indicates whether to show or ' hide the rows in the GridView control. The sender parameter ' contains the control that raised the event. Dim showCheckBox As CheckBox = CType(sender, CheckBox) ' Show or hide the rows of the GridView control based ' on the check box value selected by the user. If showCheckBox.Checked Then ShowRows(True) Else ShowRows(False) End If End Sub Sub ShowRows(ByVal show As Boolean) ' Iterate through the Rows collection of the GridView ' control and show or hide the rows based on the value ' of the show parameter. Dim row As GridViewRow For Each row In AuthorsGridView.Rows row.Visible = show Next End Sub </script> <html> <body> <form runat="server"> <h3>TemplateField HeaderTemplate Example</h3> <!-- Populate the Columns collection declaratively. --> <!-- Create a TemplateField column field that contains --> <!-- a CheckBox control in the header section to show or --> <!-- hide the rows in the GridView control. --> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="False" width="250" runat="server"> <columns> <asp:templatefield> <headerstyle backcolor="Navy" forecolor="White"/> <itemtemplate> <%#Eval("au_fname")%> <%#Eval("au_lname")%> </itemtemplate> <headertemplate> <asp:checkbox id="ShowAllCheckBox" text="Show All" checked="True" autopostback="true" oncheckedchanged="SelectAllCheckBox_CheckedChanged" runat="server"/> </headertemplate> </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_id], [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void SelectAllCheckBox_CheckedChanged(Object sender, EventArgs e) { // Get the CheckBox control that indicates whether to show or // hide the rows in the GridView control. The sender parameter // contains the control that raised the event. CheckBox showCheckBox = (CheckBox)sender; // Show or hide the rows of the GridView control based // on the check box value selected by the user. if (showCheckBox.Checked) { ShowRows (true); } else { ShowRows (false); } } void ShowRows(bool show) { // Iterate through the Rows collection of the GridView // control and show or hide the rows based on the value // of the show parameter. foreach(GridViewRow row in AuthorsGridView.Rows) { row.Visible = show; } } </script> <html> <body> <form runat="server"> <h3>TemplateField HeaderTemplate Example</h3> <!-- Populate the Columns collection declaratively. --> <!-- Create a TemplateField column field that contains --> <!-- a CheckBox control in the header section to show or --> <!-- hide the rows in the GridView control. --> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="False" width="250" runat="server"> <columns> <asp:templatefield> <headerstyle backcolor="Navy" forecolor="White"/> <itemtemplate> <%#Eval("au_fname")%> <%#Eval("au_lname")%> </itemtemplate> <headertemplate> <asp:checkbox id="ShowAllCheckBox" text="Show All" checked="True" autopostback="true" oncheckedchanged="SelectAllCheckBox_CheckedChanged" runat="server"/> </headertemplate> </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_id], [au_lname], [au_fname], [address], [city], [state], [zip], [contract] 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTemplateField.HeaderTemplate プロパティを検索する場合は、下記のリンクをクリックしてください。

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