ListView.GroupTemplate 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 ListView 控制項中群組容器的使用者定義內容。
public:
virtual property System::Web::UI::ITemplate ^ GroupTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.ListViewItem))]
public virtual System.Web.UI.ITemplate GroupTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.ListViewItem))>]
member this.GroupTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property GroupTemplate As ITemplate
屬性值
物件,包含 ListView 控制項中群組容器的自訂內容。 預設值為 null
,表示這個屬性尚未設定。
- 屬性
範例
下列範例示範如何使用 屬性, ListView 在控件 GroupTemplate 中建立磚版面配置。
<%@ 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 id="Head1" runat="server">
<title>ListView Tiled Layout Example</title>
<style type="text/css">
.header
{
background-color:#B0C4DE;
border-top:solid 1px #9dbbcc;
border-bottom:solid 1px #9dbbcc;
}
.separator { border-right: 1px solid #ccc; }
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>ListView Tiled Layout Example</h3>
<asp:ListView ID="ProductsListView"
DataSourceID="ProductsDataSource"
GroupItemCount="2"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" runat="server" id="tblProducts">
<tr runat="server" class="header">
<th runat="server" colspan="3">PRODUCTS LIST</th>
</tr>
<tr runat="server" id="groupPlaceholder" />
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="ProductsRow">
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<GroupSeparatorTemplate>
<tr runat="server">
<td colspan="3"><hr /></td>
</tr>
</GroupSeparatorTemplate>
<ItemTemplate>
<td align="center" style="width:300px" runat="server">
<asp:HyperLink ID="ProductLink" runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# "ProductDetails.aspx?productID=" + Eval("ProductID") %>' /><br />
<asp:Image ID="ProductImage" runat="server"
ImageUrl='<%# "~/images/thumbnails/" + Eval("ThumbnailPhotoFileName") %>' /><br />
<b>Price:</b>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("ListPrice", "{0:c}")%>' /><br />
</td>
</ItemTemplate>
<ItemSeparatorTemplate>
<td class="separator" runat="server"> </td>
</ItemSeparatorTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server" ID="ProductsDataPager"
PagedControlID="ProductsListView">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Button"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ProductsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT P.ProductID, P.Name, P.Color, P.ListPrice,
PF.ThumbnailPhotoFileName
FROM Production.Product AS P
INNER JOIN Production.ProductProductPhoto AS PPF ON P.ProductID = PPF.ProductID
INNER JOIN Production.ProductPhoto AS PF ON PPF.ProductPhotoID = PF.ProductPhotoID">
</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 id="Head1" runat="server">
<title>ListView Tiled Layout Example</title>
<style type="text/css">
.header
{
background-color:#B0C4DE;
border-top:solid 1px #9dbbcc;
border-bottom:solid 1px #9dbbcc;
}
.separator { border-right: 1px solid #ccc; }
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>ListView Tiled Layout Example</h3>
<asp:ListView ID="ProductsListView"
DataSourceID="ProductsDataSource"
GroupItemCount="2"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" runat="server" id="tblProducts">
<tr runat="server" class="header">
<th runat="server" colspan="3">PRODUCTS LIST</th>
</tr>
<tr runat="server" id="groupPlaceholder" />
</table>
</LayoutTemplate>
<GroupTemplate>
<tr runat="server" id="ProductsRow">
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<GroupSeparatorTemplate>
<tr runat="server">
<td colspan="3"><hr /></td>
</tr>
</GroupSeparatorTemplate>
<ItemTemplate>
<td align="center" style="width:300px" runat="server">
<asp:HyperLink ID="ProductLink" runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# "ProductDetails.aspx?productID=" & Eval("ProductID") %>' /><br />
<asp:Image ID="ProductImage" runat="server"
ImageUrl='<%# "~/images/thumbnails/" & Eval("ThumbnailPhotoFileName") %>' /><br />
<b>Price:</b>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("ListPrice", "{0:c}")%>' /><br />
</td>
</ItemTemplate>
<ItemSeparatorTemplate>
<td class="separator" runat="server"> </td>
</ItemSeparatorTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server" ID="ProductsDataPager"
PagedControlID="ProductsListView">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Button"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ProductsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT P.ProductID, P.Name, P.Color, P.ListPrice,
PF.ThumbnailPhotoFileName
FROM Production.Product AS P
INNER JOIN Production.ProductProductPhoto AS PPF ON P.ProductID = PPF.ProductID
INNER JOIN Production.ProductPhoto AS PF ON PPF.ProductPhotoID = PF.ProductPhotoID">
</asp:SqlDataSource>
</form>
</body>
</html>
備註
GroupTemplate使用 屬性在控件中ListView建立磚版面配置。 在圖格式表格配置中,專案會水準重複於數據列中。 項目重複的次數是由 屬性指定 GroupItemCount 。
若要以宣告方式指定群組容器的範本,請在控件內ListView新增 GroupTemplate
專案。 然後,您可以將範本的內容新增至 GroupTemplate
元素。
屬性 GroupTemplate 必須包含數據項的佔位元,例如數據表單元格 () td
、 div
或元素 span
。 這個佔位元的屬性必須 runat
設定為 「server」 ,而 ID
屬性設定為屬性的值 ItemPlaceholderID 。 在運行時間,ListView控件會將佔位元取代為和 AlternatingItemTemplate 範本中ItemTemplate每個專案所定義的內容。