DetailsViewPageEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 PageIndexChanging 事件的資料。
public ref class DetailsViewPageEventArgs : System::ComponentModel::CancelEventArgs
public class DetailsViewPageEventArgs : System.ComponentModel.CancelEventArgs
type DetailsViewPageEventArgs = class
inherit CancelEventArgs
Public Class DetailsViewPageEventArgs
Inherits CancelEventArgs
- 繼承
範例
下列程式碼範例示範如何在使用者嘗試在控制項處於編輯模式時,使用 DetailsViewPageEventArgs 傳遞給事件的事件處理常式 PageIndexChanging 物件來取消分頁 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 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>
備註
DetailsView控制項 PageIndexChanging 會在按一下控制項內的按鈕 (按鈕 (按鈕時引發事件,其中其 CommandName
屬性設定為 「Page」) ,但在控制項處理分頁作業之前 DetailsView 。 這可讓您提供事件處理常式來執行自訂常式,例如每當發生此事件時取消分頁作業。
注意
呼叫器按鈕通常位於 控制項的 DetailsView 呼叫器資料列中。
DetailsViewPageEventArgs物件會傳遞至事件處理常式,可讓您判斷使用者所選取頁面的索引,並指出是否應該取消分頁作業。 若要判斷使用者所選取頁面的索引,請使用 NewPageIndex 屬性。 若要取消分頁作業,請將 Cancel 物件的 屬性 DetailsViewPageEventArgs 設定為 true
。
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。
如需 DetailsViewPageEventArgs 類別之執行個體的初始屬性值清單,請參閱 DetailsViewPageEventArgs 建構函式。
建構函式
DetailsViewPageEventArgs(Int32) |
初始化 DetailsViewPageEventArgs 類別的新執行個體。 |
屬性
Cancel |
取得或設定值,這個值表示是否應該取消事件。 (繼承來源 CancelEventArgs) |
NewPageIndex |
取得或設定要在 DetailsView 控制項中顯示的新頁面索引。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |