DetailsViewPageEventArgs.NewPageIndex Eigenschaft

Definition

Ruft den Index der anzuzeigenden neuen Seite im DetailsView-Steuerelement ab oder legt ihn fest.

public:
 property int NewPageIndex { int get(); void set(int value); };
public int NewPageIndex { get; set; }
member this.NewPageIndex : int with get, set
Public Property NewPageIndex As Integer

Eigenschaftswert

Der Index der neuen anzuzeigenden Seite im DetailsView-Steuerelement.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die NewPageIndex -Eigenschaft verwendet wird, um den Index der vom Benutzer ausgewählten Seite zu bestimmen.


<%@ 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 CustomerDetailsView_PageIndexChanging(Object sender, DetailsViewPageEventArgs e)
  {
    // Cancel the paging operation if the DetailsView control 
    // in edit mode.
    if (CustomerDetailsView.CurrentMode == DetailsViewMode.Edit)
    {
      e.Cancel = true;
      
      // Display an error message.
      int newPage = e.NewPageIndex + 1;
      MessageLabel.Text = "Please update the current record before to moving to page " + 
        newPage.ToString() + ".";
    }
  }

  void CustomerDetailsView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
  {
    // Clear the message label when the user cancels edit mode.
    if (e.CancelingEdit)
    {
      MessageLabel.Text = "";
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsViewPageEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewPageEventArgs Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogenerateeditbutton="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          onpageindexchanging="CustomerDetailsView_PageIndexChanging" 
          onmodechanging="CustomerDetailsView_ModeChanging"
          runat="server">
            
          <pagersettings position="Bottom"/> 
                    
        </asp:detailsview>
        
        <br/>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- 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"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID"
          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 CustomerDetailsView_PageIndexChanging(ByVal sender As Object, ByVal e As DetailsViewPageEventArgs)
  
    ' Cancel the paging operation if the DetailsView control 
    ' in edit mode.
    If CustomerDetailsView.CurrentMode = DetailsViewMode.Edit Then
    
      e.Cancel = True
      
      ' Display an error message.
      Dim newPage As Integer = e.NewPageIndex + 1
      MessageLabel.Text = "Please update the current record before to moving to page " & _
        newPage.ToString() & "."
    
    End If
      
  End Sub

  Sub CustomerDetailsView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
  
    ' Clear the message label when the user cancels edit mode.
    If e.CancelingEdit Then
    
      MessageLabel.Text = ""
    
    End If
      
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsViewPageEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewPageEventArgs Example</h3>
                       
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogenerateeditbutton="true"
          datakeynames="CustomerID"   
          allowpaging="true"
          onpageindexchanging="CustomerDetailsView_PageIndexChanging" 
          onmodechanging="CustomerDetailsView_ModeChanging"
          runat="server">
            
          <pagersettings position="Bottom"/> 
                    
        </asp:detailsview>
        
        <br/>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- 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"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID"
          connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

Hinweise

Da das PageIndexChanging Ereignis auftritt, bevor das DetailsView Steuerelement den Auslagerungsvorgang ausführt, enthält die PageIndex -Eigenschaft des Steuerelements den Index der zuvor angezeigten Seite und kann nicht verwendet werden, um den Index der vom Benutzer ausgewählten Seite zu bestimmen. Verwenden Sie die NewPageIndex -Eigenschaft, um den Seitenindex zu bestimmen. Sie können diese Eigenschaft auch verwenden, um den vom Benutzer ausgewählten Seitenindex programmgesteuert zu überschreiben, indem Sie ihn auf einen anderen Wert festlegen.

Gilt für:

Weitere Informationen