DetailsView.PageIndexChanged Událost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Nastane, když se hodnota PageIndex vlastnosti změní po operaci stránkování.
public:
event EventHandler ^ PageIndexChanged;
public event EventHandler PageIndexChanged;
member this.PageIndexChanged : EventHandler
Public Custom Event PageIndexChanged As EventHandler
Event Type
Příklady
Následující příklad kódu ukazuje, jak pomocí PageIndexChanged události vrátit DetailsView do režimu jen pro čtení, když uživatel přejde na jiný záznam.
<%@ 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>
Poznámky
Ovládací DetailsView prvek vyvolá PageIndexChanged událost, když se v ovládacím prvku klikne tlačítko pager (tlačítko s jeho CommandName vlastností nastavenou na "Page") v ovládacím prvku, ale po DetailsView zpracování operace stránkování ovládací prvek. To vám umožní poskytnout obslužnou rutinu události, která provádí vlastní rutinu při každé výskytu této události.
Poznámka:
Tato událost není vyvolána při programovém PageIndex nastavení vlastnosti.
Tlačítka Pager se obvykle nacházejí v řádku DetailsView pageru ovládacího prvku. Tato událost se často používá k synchronizaci DetailsView ovládacího prvku s ovládacím GridView prvku nebo k nastavení chování DetailsView ovládacího prvku po operaci stránkování.
Další informace o zpracování událostí naleznete v tématu Zpracování a vyvolávání událostí.