GridView.PageIndexChanged 이벤트

정의

페이저 단추 중 하나를 클릭하면 GridView 컨트롤이 페이징 작업을 처리한 후에 이 이벤트가 발생합니다.

public:
 event EventHandler ^ PageIndexChanged;
public event EventHandler PageIndexChanged;
member this.PageIndexChanged : EventHandler 
Public Custom Event PageIndexChanged As EventHandler 

이벤트 유형

예제

다음 예제에서는 사용 PageIndexChanged 하는 방법에 설명 합니다 호출기 행에서 사용자가 선택한 페이지 번호를 표시 하는 이벤트입니다.


<%@ 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 CustomersGridView_DataBound(Object sender, EventArgs e)
  {
    if (!IsPostBack)
    {
      // Call a helper method to display the current page number 
      // when the page is first loaded.
      DisplayCurrentPage();
    }
  }

  void CustomersGridView_PageIndexChanged(Object sender, EventArgs e)
  {
    // Call a helper method to display the current page number 
    // when the user navigates to a different page.
    DisplayCurrentPage();
  }

  void DisplayCurrentPage()
  {
    // Calculate the current page number.
    int currentPage = CustomersGridView.PageIndex + 1;

    // Display the current page number. 
    Message.Text = "Page " + currentPage.ToString() + " of " + 
      CustomersGridView.PageCount.ToString() + ".";
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView PageIndexChanged Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView PageIndexChanged Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true"
        ondatabound="CustomersGridView_DataBound"
        onpageindexchanged="CustomersGridView_PageIndexChanged"
        runat="server">
                
        <pagersettings mode="Numeric"
          position="Bottom"           
          pagebuttoncount="10"/>
                      
        <pagerstyle backcolor="LightBlue"/>
                
      </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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        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 CustomersGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
      
    If Not IsPostBack Then
    
      ' Call a helper method to display the current page number 
      ' when the page is first loaded.
      DisplayCurrentPage()
      
    End If
    
  End Sub

  Sub CustomersGridView_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
  
    ' Call a helper method to display the current page number 
    ' when the user navigates to a different page.
    DisplayCurrentPage()
  
  End Sub

  Sub DisplayCurrentPage()
  
    ' Calculate the current page number.
    Dim currentPage As Integer = CustomersGridView.PageIndex + 1

    ' Display the current page number. 
    Message.Text = "Page " & currentPage.ToString() & " of " & _
      CustomersGridView.PageCount.ToString() & "."
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView PageIndexChanged Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView PageIndexChanged Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true"
        ondatabound="CustomersGridView_DataBound"
        onpageindexchanged="CustomersGridView_PageIndexChanged"
        runat="server">
                
        <pagersettings mode="Numeric"
          position="Bottom"           
          pagebuttoncount="10"/>
                      
        <pagerstyle backcolor="LightBlue"/>
                
      </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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

설명

이벤트는 PageIndexChanged 호출기 단추 중 하나를 클릭할 때 발생하지만 컨트롤이 GridView 페이징 작업을 처리한 후에 발생합니다. 이렇게 하면 이 이벤트가 발생할 때마다 사용자 지정 페이징 작업과 같은 사용자 지정 루틴을 수행하는 이벤트 처리 메서드를 제공할 수 있습니다.

사용자가 선택한 페이지의 인덱스 확인 하려면 사용 된 PageIndex 속성은 컨트롤입니다 GridView .

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보