DetailsViewPageEventArgs Třída

Definice

Poskytuje data pro událost PageIndexChanging.

public ref class DetailsViewPageEventArgs : System::ComponentModel::CancelEventArgs
public class DetailsViewPageEventArgs : System.ComponentModel.CancelEventArgs
type DetailsViewPageEventArgs = class
    inherit CancelEventArgs
Public Class DetailsViewPageEventArgs
Inherits CancelEventArgs
Dědičnost
DetailsViewPageEventArgs

Příklady

Následující příklad kódu ukazuje, jak použít DetailsViewPageEventArgs objekt předaný obslužné rutině události pro PageIndexChanging událost ke zrušení operace stránkování, když se uživatel pokusí přejít na jinou stránku, zatímco DetailsView ovládací prvek je v režimu úprav.


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

Poznámky

Ovládací DetailsView prvek vyvolá PageIndexChanging událost, když se klikne na tlačítko pager (tlačítko s jeho CommandName vlastností nastavenou na "Stránka") v rámci ovládacího prvku, ale před tím, než DetailsView ovládací prvek zpracuje operaci stránkování. To vám umožní poskytnout obslužnou rutinu události, která provádí vlastní rutinu, například zrušení operace stránkování, kdykoli dojde k této události.

Poznámka

Tlačítka stránkování jsou obvykle umístěna v řádku DetailsView pageru ovládacího prvku.

DetailsViewPageEventArgs Objekt je předán obslužné rutině události, což vám umožní určit index stránky vybrané uživatelem a určit, zda má být operace stránkování zrušena. K určení indexu stránky vybrané uživatelem použijte NewPageIndex vlastnost . Chcete-li zrušit operaci stránkování, nastavte Cancel vlastnost objektu DetailsViewPageEventArgs na truehodnotu .

Další informace o zpracování událostí najdete v tématu Zpracování a vyvolávání událostí.

Seznam počátečních hodnot vlastností pro instanci DetailsViewPageEventArgs třídy naleznete v konstruktoru DetailsViewPageEventArgs .

Konstruktory

DetailsViewPageEventArgs(Int32)

Inicializuje novou instanci DetailsViewPageEventArgs třídy.

Vlastnosti

Cancel

Získá nebo nastaví hodnotu označující, zda má být událost zrušena.

(Zděděno od CancelEventArgs)
NewPageIndex

Získá nebo nastaví index nové stránky k zobrazení v ovládacím DetailsView prvku.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také