FormView.PageCount 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
데이터 소스의 모든 레코드를 표시하는 데 필요한 전체 페이지 수를 가져옵니다.
public:
virtual property int PageCount { int get(); };
[System.ComponentModel.Browsable(false)]
public virtual int PageCount { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PageCount : int
Public Overridable ReadOnly Property PageCount As Integer
속성 값
내부 데이터 소스의 항목 수입니다.
- 특성
예제
다음 예제에서는 컨트롤에 PageCount 표시 된 레코드의 총 수를 확인 하려면 속성을 사용 하는 방법을 보여 줍니다.
<%@ 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">
void EmployeeFormView_DataBound(Object sender, EventArgs e)
{
// Get the pager row.
FormViewRow pagerRow = EmployeeFormView.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 = EmployeeFormView.PageIndex + 1;
int count = EmployeeFormView.PageCount;
pageNum.Text = page.ToString();
totalNum.Text = count.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormView PagerTemplate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormView PagerTemplate Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
ondatabound="EmployeeFormView_DataBound"
runat="server">
<itemtemplate>
<table>
<tr>
<td>
<asp:image id="EmployeeImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td>
<h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>
<%# Eval("Title") %>
</td>
</tr>
</table>
</itemtemplate>
<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>
<pagersettings position="Bottom"
mode="NextPrevious"/>
</asp:formview>
<!-- 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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</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">
Sub EmployeeFormView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
' Get the pager row.
Dim pagerRow As FormViewRow = EmployeeFormView.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 = EmployeeFormView.PageIndex + 1
Dim count As Integer = EmployeeFormView.PageCount
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>FormView PagerTemplate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormView PagerTemplate Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
ondatabound="EmployeeFormView_DataBound"
runat="server">
<itemtemplate>
<table>
<tr>
<td>
<asp:image id="EmployeeImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td>
<h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>
<%# Eval("Title") %>
</td>
</tr>
</table>
</itemtemplate>
<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>
<pagersettings position="Bottom"
mode="NextPrevious"/>
</asp:formview>
<!-- 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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
설명
페이징 기능을 사용하는 경우(속성이 설정된 true
경우AllowPaging) 속성을 사용하여 PageCount 기본 데이터 원본의 총 레코드 수를 확인합니다.
참고
컨트롤은 FormView 한 번에 하나의 레코드만 표시하므로 이 값은 데이터 원본의 모든 레코드를 표시하는 데 필요한 총 페이지 수에 해당합니다. 이 값은 데이터 바인딩이 발생할 때까지 정확하지 않습니다.
기본 데이터 원본에서 현재 레코드의 인덱스 확인 하려면 속성을 사용 합니다 PageIndex .