DetailsView.PageIndexChanged 事件

定义

PageIndex 属性的值在分页操作后更改时发生。

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

事件类型

示例

下面的代码示例演示如何在用户导航到另一条记录时使用 PageIndexChanged 事件将 返回到 DetailsView 只读模式。


<%@ 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 CustomerDetailView_PageIndexChanged(Object sender, EventArgs e)
  {
    // By default, if the DetailsView control is in edit mode and
    // user navigates to another page, the DetailsView control
    // remains in edit mode. In this example, the ChangeMode 
    // method is used to put the DetailsView control in read-only  
    // mode whenever the user navigates to another record.
      CustomerDetailView.ChangeMode(DetailsViewMode.ReadOnly);
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ChangeMode Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ChangeMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          OnPageIndexChanged="CustomerDetailView_PageIndexChanged"
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </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">

    Sub CustomerDetailView_PageIndexChanged(ByVal sender As Object, _
        ByVal e As EventArgs)
        ' By default, if the DetailsView control is in edit mode and
        ' user navigates to another page, the DetailsView control
        ' remains in edit mode. In this example, the ChangeMode 
        ' method is used to put the DetailsView control in read-only  
        ' mode whenever the user navigates to another record.
        CustomerDetailView.ChangeMode(DetailsViewMode.ReadOnly)
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ChangeMode Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ChangeMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          OnPageIndexChanged="CustomerDetailView_PageIndexChanged"
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </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>

注解

DetailsView当页导航按钮 (其属性设置为“Page”的按钮CommandName时,控件将引发 PageIndexChanged 事件) 控件内的单击,但在控件处理分页操作之后DetailsView。 这允许你提供一个事件处理程序,每当发生此事件时执行自定义例程。

注意

以编程方式设置 属性时,不会引发此 PageIndex 事件。

寻呼按钮通常位于控件的 DetailsView 页导航行中。 此事件通常用于将控件与GridView控件同步DetailsView,或在分页操作之后设置控件的行为DetailsView

有关如何处理事件的详细信息,请参阅 处理和引发事件

适用于

另请参阅