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

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

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

FooterTemplate プロパティを使用して、GridView コントロールの TemplateField フィールド列に表示されるフッター セクションのカスタム テンプレートを作成するコード例を次に示します。このテンプレートは、TemplateField フィールド列に値の合計を表示します。
<%@ Page language="VB" %> <script runat="server"> ' Create a variable to store the order total. Private orderTotal As Decimal = 0.0 Sub OrderGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.Footer Then ' Get the OrderTotalLabel Label control in the footer row. Dim total As Label = CType(e.Row.FindControl("OrderTotalLabel"), Label) ' Display the grand total of the order formatted as currency. If (Not total Is Nothing) total.Text = orderTotal.ToString("c") End If End If End Sub Sub OrderGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then ' Get the cell that contains the item total. Dim cell As TableCell = e.Row.Cells(2) ' Get the DataBoundLiteralControl control that contains the ' data bound value. Dim boundControl As DataBoundLiteralControl = CType(cell.Controls(0), DataBoundLiteralControl) ' Remove the '$' character so that the type converter works properly. Dim itemTotal As String = boundControl.Text.Replace("$", "") ' Add the total for an item (row) to the order total. orderTotal += Convert.ToDecimal(itemTotal) End If End Sub </script> <html> <body> <form runat="server"> <h3>TemplateField FooterTemplate Example</h3> <!-- Populate the Columns collection declaratively. --> <!-- Create a custom TemplateField column that uses --> <!-- two Label controls to display an author's first and --> <!-- last name in the same column. --> <asp:gridview id="OrderGridView" datasourceid="OrderSqlDataSource" autogeneratecolumns="False" showfooter="true" onrowcreated="OrderGridView_RowCreated" onrowdatabound="OrderGridView_RowDataBound" runat="server"> <columns> <asp:boundfield datafield="UnitPrice" itemstyle-horizontalalign="Right" headertext="Unit Price" dataformatstring="{0:c}"/> <asp:boundfield datafield="Quantity" itemstyle-horizontalalign="Right" headertext="Quantity"/> <asp:templatefield headertext="Total" itemstyle-horizontalalign="Right" footerstyle-horizontalalign="Right" footerstyle-backcolor="Blue" footerstyle-forecolor="White"> <itemtemplate> <%#Eval("Total", "{0:c}") %> </itemtemplate> <footertemplate> <asp:label id="OrderTotalLabel" runat="server"/> </footertemplate> </asp:templatefield> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. --> <asp:sqldatasource id="OrderSqlDataSource" selectcommand="SELECT [OrderID], [UnitPrice], [Quantity], [UnitPrice]*[Quantity] As [Total] FROM [order details] WHERE [OrderID]=10248" connectionstring="server=localhost;database=northwind;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> // Create a variable to store the order total. private Decimal orderTotal = 0.0M; void OrderGridView_RowCreated(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { // Get the OrderTotalLabel Label control in the footer row. Label total = (Label)e.Row.FindControl("OrderTotalLabel"); // Display the grand total of the order formatted as currency. if (total != null) { total.Text = orderTotal.ToString("c"); } } } void OrderGridView_RowDataBound(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Get the cell that contains the item total. TableCell cell = e.Row.Cells[2]; // Get the DataBoundLiteralControl control that contains the // data-bound value. DataBoundLiteralControl boundControl = (DataBoundLiteralControl)cell.Controls[0]; // Remove the '$' character so that the type converter works properly. String itemTotal = boundControl.Text.Replace("$", ""); // Add the total for an item (row) to the order total. orderTotal += Convert.ToDecimal(itemTotal); } } </script> <html> <body> <form runat="server"> <h3>TemplateField FooterTemplate Example</h3> <!-- Populate the Columns collection declaratively. --> <!-- Create a custom TemplateField column that uses --> <!-- two Label controls to display an author's first and --> <!-- last name in the same column. --> <asp:gridview id="OrderGridView" datasourceid="OrderSqlDataSource" autogeneratecolumns="False" showfooter="true" onrowcreated="OrderGridView_RowCreated" onrowdatabound="OrderGridView_RowDataBound" runat="server"> <columns> <asp:boundfield datafield="UnitPrice" itemstyle-horizontalalign="Right" headertext="Unit Price" dataformatstring="{0:c}"/> <asp:boundfield datafield="Quantity" itemstyle-horizontalalign="Right" headertext="Quantity"/> <asp:templatefield headertext="Total" itemstyle-horizontalalign="Right" footerstyle-horizontalalign="Right" footerstyle-backcolor="Blue" footerstyle-forecolor="White"> <itemtemplate> <%#Eval("Total", "{0:c}") %> </itemtemplate> <footertemplate> <asp:label id="OrderTotalLabel" runat="server"/> </footertemplate> </asp:templatefield> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. --> <asp:sqldatasource id="OrderSqlDataSource" selectcommand="SELECT [OrderID], [UnitPrice], [Quantity], [UnitPrice]*[Quantity] As [Total] FROM [order details] WHERE [OrderID]=10248" connectionstring="server=localhost;database=northwind;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.FooterTemplate プロパティのページへのリンク