DetailsView.PagerSettings 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个对 PagerSettings 对象的引用,使用该对象可以设置 DetailsView 控件中的页导航按钮的属性。
public:
virtual property System::Web::UI::WebControls::PagerSettings ^ PagerSettings { System::Web::UI::WebControls::PagerSettings ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.PagerSettings PagerSettings { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.PagerSettings : System.Web.UI.WebControls.PagerSettings
Public Overridable ReadOnly Property PagerSettings As PagerSettings
属性值
一个对 PagerSettings 的引用,使用该对象可以设置 DetailsView 控件中的页导航按钮的属性。
- 属性
示例
下面的代码示例演示如何使用 PagerSettings 属性指定寻呼行的属性。
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void CustomerDetailView_DataBound(object sender, EventArgs e)
{
// Get the pager row.
DetailsViewRow pagerRow = CustomerDetailView.BottomPagerRow;
// Get the Label controls that display the current page information
// from the pager row.
Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");
if ((pageNum != null) && (totalNum != null))
{
// Update the Label controls with the current page values.
int page = CustomerDetailView.DataItemIndex + 1;
int count = CustomerDetailView.DataItemCount;
pageNum.Text = page.ToString();
totalNum.Text = count.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView PagerTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView PagerTemplate Example</h3>
<!-- Notice that the LinkButton controls in the pager -->
<!-- template have their CommandName properties set. -->
<!-- The DetailsView control automatically recognizes -->
<!-- certain command names and performs the appropriate -->
<!-- operation. In this example, the CommandName -->
<!-- properties are set "Page" and the CommandArgument -->
<!-- properties are set to "Next" and "Prev", which -->
<!-- causes the DetailsView control to navigate to the -->
<!-- next and previous record, respectively. -->
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
autogeneraterows="true"
allowpaging="true"
runat="server" OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagerstyle VerticalAlign="Bottom" />
<pagertemplate>
<table width="100%">
<tr>
<td>
<asp:LinkButton id="PreviousButton"
text="<"
CommandName="Page"
CommandArgument="Prev"
runat="Server"/>
<asp:LinkButton id="NextButton"
text=">"
CommandName="Page"
CommandArgument="Next"
runat="Server"/>
</td>
<td align="right">
Page <asp:Label id="PageNumberLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" />
</td>
</tr>
</table>
</pagertemplate>
</asp:detailsview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the web.config file. -->
<asp:SqlDataSource ID="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</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">
<script runat="server">
Protected Sub CustomerDetailView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
' Get the pager row.
Dim pagerRow As DetailsViewRow = CustomerDetailView.BottomPagerRow
' Get the Label controls that display the current page information
' from the pager row.
Dim pageNum As Label = CType(pagerRow.Cells(0).FindControl("PageNumberLabel"), Label)
Dim totalNum As Label = CType(pagerRow.Cells(0).FindControl("TotalPagesLabel"), Label)
If (pageNum IsNot Nothing) And (totalNum IsNot Nothing) Then
' Update the Label controls with the current page values.
Dim page As Integer = CustomerDetailView.DataItemIndex + 1
Dim count As Integer = CustomerDetailView.DataItemCount
pageNum.Text = page.ToString()
totalNum.Text = count.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsView PagerTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView PagerTemplate Example</h3>
<!-- Notice that the LinkButton controls in the pager -->
<!-- template have their CommandName properties set. -->
<!-- The DetailsView control automatically recognizes -->
<!-- certain command names and performs the appropriate -->
<!-- operation. In this example, the CommandName -->
<!-- properties are set "Page" and the CommandArgument -->
<!-- properties are set to "Next" and "Prev", which -->
<!-- causes the DetailsView control to navigate to the -->
<!-- next and previous record, respectively. -->
<asp:detailsview id="CustomerDetailView"
datasourceid="DetailsViewSource"
autogeneraterows="true"
allowpaging="true"
runat="server" OnDataBound="CustomerDetailView_DataBound">
<headerstyle backcolor="Navy"
forecolor="White"/>
<pagerstyle VerticalAlign="Bottom" />
<pagertemplate>
<table width="100%">
<tr>
<td>
<asp:LinkButton id="PreviousButton"
text="<"
CommandName="Page"
CommandArgument="Prev"
runat="Server"/>
<asp:LinkButton id="NextButton"
text=">"
CommandName="Page"
CommandArgument="Next"
runat="Server"/>
</td>
<td align="right">
Page <asp:Label id="PageNumberLabel" runat="server" />
of <asp:Label id="TotalPagesLabel" runat="server" />
</td>
</tr>
</table>
</pagertemplate>
</asp:detailsview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the web.config file. -->
<asp:SqlDataSource ID="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
注解
使用 PagerSettings 属性控制控件中 DetailsView 寻呼行的设置。 通过将属性设置为) 并包含允许用户导航到控件中不同记录的控件,将分页功能设置为 AllowPaging true
(时,将显示寻呼行。 此属性为只读;但是,可以设置它返回的对象的属性 PagerSettings 。 可以在窗体 Property-Subproperty
中以声明方式设置属性,例如 Subproperty
,对象的属性 PagerSettings () PagerSetting-Mode
。 还可以以编程方式在窗体 Property.Subproperty
中设置属性,例如 PagerSetting.Mode
) (。 常见设置通常包括寻呼行的显示模式和导航控件的自定义文本或图像。