DetailsView.PageIndexChanged Zdarzenie

Definicja

Występuje, gdy wartość PageIndex właściwości zmienia się po operacji stronicowania.

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

Typ zdarzenia

Przykłady

W poniższym przykładzie kodu pokazano, jak używać PageIndexChanged zdarzenia, aby przywrócić DetailsView tryb tylko do odczytu, gdy użytkownik przejdzie do innego rekordu.


<%@ 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>

Uwagi

Kontrolka DetailsView zgłasza PageIndexChanged zdarzenie, gdy przycisk pager (przycisk z jego CommandName właściwością ustawioną na "Page") w kontrolce jest klikany, ale po DetailsView kontrolce obsługuje operację stronicowania. Dzięki temu można udostępnić procedurę obsługi zdarzeń, która wykonuje niestandardową procedurę za każdym razem, gdy wystąpi to zdarzenie.

Uwaga

To zdarzenie nie jest zgłaszane podczas programowego ustawiania PageIndex właściwości.

Przyciski pagera znajdują się zwykle w wierszu stronicatora DetailsView kontrolki. To zdarzenie jest często używane do synchronizowania DetailsView kontrolki z kontrolką GridView lub ustawiania zachowania DetailsView kontrolki po operacji stronicowania.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Dotyczy

Zobacz też