GridView.PagerTemplate 속성

정의

GridView 컨트롤의 페이저 행에 대한 사용자 지정 콘텐츠를 가져오거나 설정합니다.

public:
 virtual property System::Web::UI::ITemplate ^ PagerTemplate { 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.GridViewRow))]
public virtual System.Web.UI.ITemplate PagerTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.GridViewRow))>]
member this.PagerTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property PagerTemplate As ITemplate

속성 값

ITemplate

페이저 행에 대한 사용자 지정 콘텐츠가 들어 있는 ITemplate입니다. 기본값은 null로, 이 속성이 설정되지 않음을 나타냅니다.

특성

예제

다음 예제에서는 사용자가 컨트롤을 사용 하 여 컨트롤을 탐색할 수 있도록 사용자 지정 호출기 템플릿을 GridView 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">

  protected void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
  {

    // Retrieve the pager row.
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
    
    // Retrieve the PageDropDownList DropDownList from the bottom 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;

  }

  protected void CustomersGridView_DataBound(Object sender, EventArgs e)
  {

    // Retrieve the pager row.
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
    
    // 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 PagerTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView PagerTemplate Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource"   
        autogeneratecolumns="true"
        allowpaging="true"
        ondatabound="CustomersGridView_DataBound"  
        runat="server">
              
        <pagerstyle forecolor="Blue"
          backcolor="LightBlue"/>
              
        <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%; text-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">

    Protected Sub PageDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    
        ' Retrieve the pager row.
        Dim pagerRow As GridViewRow = CustomersGridView.BottomPagerRow
    
        ' 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
    
    Protected Sub CustomersGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
    
        ' Retrieve the pager row.
        Dim pagerRow As GridViewRow = CustomersGridView.BottomPagerRow
    
        ' 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 PagerTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView PagerTemplate Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource"   
        autogeneratecolumns="true"
        allowpaging="true"
        ondatabound="CustomersGridView_DataBound"  
        runat="server">
              
        <pagerstyle forecolor="Blue"
          backcolor="LightBlue"/>
              
        <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%; text-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로 GridView 설정된 경우) 호출기 행이 컨트롤에 AllowPaging 표시됩니다. 호출기 행에는 사용자가 컨트롤의 다른 페이지로 이동할 수 있는 컨트롤이 포함되어 있습니다. 기본 제공 페이저 행 사용자 인터페이스(UI)를 사용하는 대신 속성을 사용하여 사용자 고유의 UI를 PagerTemplate 정의할 수 있습니다.

참고

속성이 PagerTemplate 설정되면 기본 제공 호출기 행 UI를 재정의합니다.

호출기 행에 대한 사용자 지정 템플릿을 지정하려면 먼저 컨트롤의 여는 태그와 닫는 태그 사이에 태그를 GridView 배치 <PagerTemplate> 합니다. 다음 태그와 닫는 사이 템플릿의 콘텐츠를 나열할 수 있습니다 <PagerTemplate> 태그입니다. 호출기 행의 모양을 제어하려면 속성을 사용합니다 PagerStyle .

일반적으로 페이징 작업을 수행하기 위해 단추 컨트롤이 호출기 템플릿에 추가됩니다. 속성이 GridView "Page"로 설정된 단추 컨트롤을 클릭하면 컨트롤 CommandName 이 페이징 작업을 수행합니다. 단추의 CommandArgument 속성은 수행할 페이징 작업의 유형을 결정합니다. 다음 표에서는 컨트롤에서 지원하는 명령 인수 값을 나열합니다 GridView .

CommandArgument Description
"다음" 다음 페이지로 이동합니다.
"Prev" 라는 이전 페이지로 이동합니다.
"First" 첫 번째 페이지로 이동합니다.
"지난" 마지막에 페이지를 탐색 합니다.
정수 값 지정된 페이지 번호로 이동합니다.

적용 대상

추가 정보