NumericPagerField.ButtonCount 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定要在 NumericPagerField 物件中顯示的按鈕數目。
public:
property int ButtonCount { int get(); void set(int value); };
public int ButtonCount { get; set; }
member this.ButtonCount : int with get, set
Public Property ButtonCount As Integer
屬性值
要在 NumericPagerField 物件中顯示的按鈕數目。 預設值為 5。
例外狀況
ButtonCount 屬性會設定為小於 1 的值。
範例
下列範例示範如何使用 ButtonCount 屬性來變更控件對象DataPager中顯示的NumericPagerField預設頁面按鈕數目。
<%@ 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>NumericPagerField Example</title>
<style type="text/css">
.PagerNormal
{
font: 9pt Verdana;
color: #0066CF;
border: solid 1px #778899;
padding: 1px 4px;
text-decoration:none;
}
.PagerCurrent
{
font: 9pt Verdana;
border: solid 1px #778899;
padding: 1px 4px;
background-color: #FFD700;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>NumericPagerField Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" id="tblContacts">
<tr runat="server">
<th runat="server">ID</th>
<th runat="server">First Name</th>
<th runat="server">Last Name</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
<br />
<asp:DataPager runat="server" ID="ContactsDataPager" PagedControlID="ContactsListView">
<Fields>
<asp:NumericPagerField
ButtonCount="10"
CurrentPageLabelCssClass="PagerCurrent"
NextPreviousButtonCssClass="PagerNormal"
NumericButtonCssClass="PagerNormal"
NextPageText=">>"
PreviousPageText="<<" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Label ID="ContactIDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
</td>
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<!-- 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="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName] FROM Person.Contact">
</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>NumericPagerField Example</title>
<style type="text/css">
.PagerNormal
{
font: 9pt Verdana;
color: #0066CF;
border: solid 1px #778899;
padding: 1px 4px;
text-decoration:none;
}
.PagerCurrent
{
font: 9pt Verdana;
border: solid 1px #778899;
padding: 1px 4px;
background-color: #FFD700;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>NumericPagerField Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
runat="server">
<LayoutTemplate>
<table cellpadding="2" width="640px" border="1" runat="server" id="tblContacts">
<tr runat="server">
<th runat="server">ID</th>
<th runat="server">First Name</th>
<th runat="server">Last Name</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
<br />
<asp:DataPager runat="server" ID="ContactsDataPager" PagedControlID="ContactsListView">
<Fields>
<asp:NumericPagerField
ButtonCount="10"
CurrentPageLabelCssClass="PagerCurrent"
NextPreviousButtonCssClass="PagerNormal"
NumericButtonCssClass="PagerNormal"
NextPageText=">>"
PreviousPageText="<<" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:Label ID="ContactIDLabel" runat="server" Text='<%# Eval("ContactID") %>' />
</td>
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<!-- 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="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName] FROM Person.Contact">
</asp:SqlDataSource>
</form>
</body>
</html>
備註
ButtonCount使用屬性可指定要顯示在物件中的NumericPagerField按鈕數目。 每個按鈕都會對應至頁碼。 NumericPagerField如果 物件有超過指定的ButtonCount頁數,控件會顯示下一頁按鈕,讓使用者存取下一組頁面。
物件 NumericPagerField 只會顯示現有頁碼的按鈕。 NumericPagerField如果對象要顯示的頁數比指定的ButtonCount數位少,控件會顯示的按鈕比這個屬性所指定的數位少。