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) がクリックされると、コントロールはページング操作をDetailsView処理した後にイベントを発生PageIndexChangedさせます。 これにより、このイベントが発生するたびにカスタム ルーチンを実行するイベント ハンドラーを提供できます。

注意

プログラムで プロパティを設定 PageIndex した場合、このイベントは発生しません。

通常、ポケットベル ボタンはコントロールのポケットベル行に DetailsView 配置されます。 このイベントは、多くの場合、コントロールとコントロールを DetailsView 同期したり、 GridView ページング操作後にコントロールの DetailsView 動作を設定したりするために使用されます。

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

適用対象

こちらもご覧ください