GridView.TopPagerRow 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
GridViewRow 컨트롤의 위쪽 페이저 행을 나타내는 GridView 개체를 가져옵니다.
public:
virtual property System::Web::UI::WebControls::GridViewRow ^ TopPagerRow { System::Web::UI::WebControls::GridViewRow ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.GridViewRow TopPagerRow { get; }
[<System.ComponentModel.Browsable(false)>]
member this.TopPagerRow : System.Web.UI.WebControls.GridViewRow
Public Overridable ReadOnly Property TopPagerRow As GridViewRow
속성 값
컨트롤의 위쪽 페이저 행을 나타내는 GridViewRow입니다.
- 특성
예제
다음 예제에서는 사용 하는 방법을 보여 줍니다.는 TopPagerRow 컨트롤의 맨 위 호출기 행에 액세스 하는 속성입니다 GridView . 속성은 TopPagerRow 호출기 행에서 컨트롤을 DropDownList 검색하는 데 사용됩니다.
<%@ 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 PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
{
// Retrieve the pager row.
GridViewRow pagerRow = CustomersGridView.TopPagerRow;
// Retrieve the PageDropDownList DropDownList from the pager row.
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
// Set the PageIndex property to display that page selected by the user.
CustomersGridView.PageIndex = pageList.SelectedIndex;
}
void CustomersGridView_DataBound(Object sender, EventArgs e)
{
// Retrieve the PagerRow.
GridViewRow pagerRow = CustomersGridView.TopPagerRow;
// Retrieve the DropDownList and Label controls from the row.
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
if(pageList != null)
{
// Create the values for the DropDownList control based on
// the total number of pages required to display the data
// source.
for(int i=0; i<CustomersGridView.PageCount; i++)
{
// Create a ListItem object to represent a page.
int pageNumber = i + 1;
ListItem item = new ListItem(pageNumber.ToString());
// If the ListItem object matches the currently selected
// page, flag the ListItem object as being selected. Because
// the DropDownList control is recreated each time the pager
// row gets created, this will persist the selected item in
// the DropDownList control.
if(i==CustomersGridView.PageIndex)
{
item.Selected = true;
}
// Add the ListItem object to the Items collection of the
// DropDownList.
pageList.Items.Add(item);
}
}
if(pageLabel != null)
{
// Calculate the current page number.
int currentPage = CustomersGridView.PageIndex + 1;
// Update the Label control with the current page information.
pageLabel.Text = "Page " + currentPage.ToString() +
" of " + CustomersGridView.PageCount.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView TopPagerRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView TopPagerRow Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
allowpaging="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<pagerstyle forecolor="Blue"
backcolor="LightBlue"/>
<pagersettings position="Top"/>
<pagertemplate>
<table width="100%">
<tr>
<td style="width:70%">
<asp:label id="MessageLabel"
forecolor="Blue"
text="Select a page:"
runat="server"/>
<asp:dropdownlist id="PageDropDownList"
autopostback="true"
onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
runat="server"/>
</td>
<td style="width:70%" align="right">
<asp:label id="CurrentPageLabel"
forecolor="Blue"
runat="server"/>
</td>
</tr>
</table>
</pagertemplate>
</asp:gridview>
<!-- 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="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</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">
Sub PageDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' Retrieve the pager row.
Dim pagerRow As GridViewRow = CustomersGridView.TopPagerRow
' Retrieve the PageDropDownList DropDownList from the bottom pager row.
Dim pageList As DropDownList = CType(pagerRow.Cells(0).FindControl("PageDropDownList"), DropDownList)
' Set the PageIndex property to display that page selected by the user.
CustomersGridView.PageIndex = pageList.SelectedIndex
End Sub
Sub CustomersGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
' Get the PagerRow.
Dim pagerRow As GridViewRow = CustomersGridView.TopPagerRow
' Retrieve the DropDownList and Label controls from the row.
Dim pageList As DropDownList = CType(pagerRow.Cells(0).FindControl("PageDropDownList"), DropDownList)
Dim pageLabel As Label = CType(pagerRow.Cells(0).FindControl("CurrentPageLabel"), Label)
If Not pageList Is Nothing Then
' Create the values for the DropDownList control based on
' the total number of pages required to display the data
' source.
Dim i As Integer
For i = 0 To CustomersGridView.PageCount - 1
' Create a ListItem object to represent a page.
Dim pageNumber As Integer = i + 1
Dim item As ListItem = New ListItem(pageNumber.ToString())
' If the ListItem object matches the currently selected
' page, flag the ListItem object as being selected. Because
' the DropDownList control is recreated each time the pager
' row gets created, this will persist the selected item in
' the DropDownList control.
If i = CustomersGridView.PageIndex Then
item.Selected = True
End If
' Add the ListItem object to the Items collection of the
' DropDownList.
pageList.Items.Add(item)
Next i
End If
If Not pageLabel Is Nothing Then
' Calculate the current page number.
Dim currentPage As Integer = CustomersGridView.PageIndex + 1
' Update the Label control with the current page information.
pageLabel.Text = "Page " & currentPage.ToString() & _
" of " & CustomersGridView.PageCount.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView TopPagerRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView TopPagerRow Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
allowpaging="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<pagerstyle forecolor="Blue"
backcolor="LightBlue"/>
<pagersettings position="Top"/>
<pagertemplate>
<table width="100%">
<tr>
<td style="width:70%">
<asp:label id="MessageLabel"
forecolor="Blue"
text="Select a page:"
runat="server"/>
<asp:dropdownlist id="PageDropDownList"
autopostback="true"
onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
runat="server"/>
</td>
<td style="width:70%" align="right">
<asp:label id="CurrentPageLabel"
forecolor="Blue"
runat="server"/>
</td>
</tr>
</table>
</pagertemplate>
</asp:gridview>
<!-- 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="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
설명
페이징을 사용하도록 설정하면(속성을 true
로 설정AllowPaging) 호출기 행이라는 추가 행이 컨트롤에 GridView 자동으로 표시됩니다. 호출기 행에는 사용자가 다른 페이지로 이동할 수 있는 컨트롤이 포함되어 있으며 컨트롤의 위쪽, 아래쪽 또는 맨 위와 아래쪽 모두에 표시될 수 있습니다. 사용 된 TopPagerRow 속성을 프로그래밍 방식으로 액세스 하는 컨트롤의 GridViewRow 위쪽 호출기 행을 나타내는 개체입니다 GridView .
참고
속성은 TopPagerRow 컨트롤이 GridView 이벤트에서 최상위 호출기 행을 만든 후에만 사용할 수 있습니다 RowCreated .
이 속성은 사용자 지정 콘텐츠를 추가할 때와 같이 위쪽 호출기 행을 프로그래밍 방식으로 조작해야 하는 경우에 일반적으로 사용됩니다. 컨트롤이 TopPagerRow 렌더링된 후에 GridView 는 속성을 수정해야 합니다. 그렇지 않으면 컨트롤이 GridView 변경 내용을 덮어쓰게 됩니다.
적용 대상
추가 정보
.NET