DetailsView.PageIndexChanged 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於 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按一下控制項時,當呼叫器按鈕 (按鈕的屬性 CommandName
設定為 「Page」) ,但在控制項處理分頁作業之後 DetailsView ,控制項就會引發 PageIndexChanged 事件。 這可讓您提供事件處理常式,以在發生此事件時執行自訂常式。
注意
當您以程式設計方式設定 PageIndex 屬性時,不會引發此事件。
呼叫器按鈕通常位於 控制項的 DetailsView 呼叫器資料列中。 這個事件通常用來將控制項與控制項同步 DetailsView 處理,或在分頁作業之後設定控制項的行為 DetailsView 。 GridView
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。