System.Web.UI.WebControls Namespace DetailsView Class
.NET Framework version 2.0
Occurs when any of the pager buttons in a DetailsView control is clicked, but before the page changes.
[ VB ]
Public Event PageIndexChanging As DetailsViewPageEventHandler
[ C# ]
public event DetailsViewPageEventHandler PageIndexChanging;
[ C++ ]
public: __event DetailsViewPageEventHandler* PageIndexChanging;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The PageIndexChanging event is raised whenever any of the buttons in the page selection element of a DetailsView control is clicked, but before the DetailsView handles the paging operation.
This allows you to provide an event-handling method that performs a custom routine, such as canceling the paging operation, whenever this event occurs.
NOTE: This event is not raised when the PageIndex property is set programmatically.
The method assigned to handle the event is passed an argument of type DetailsViewPageEventArgs object containing data related to this event. The following DetailsViewPageEventArgs properties provide information specific to this event.
Property |
Description |
Cancel |
Gets or sets a value indicating whether the event should be canceled ( Inherited from CancelEventArgs ) |
NewPageIndex |
Gets the index of the page selected by the user in the page selection element of the DetailsView control. |
The following example demonstrates how to use the PageIndexChanging event to cancel a paging operation.
<script runat = "server">
void EmployeeDetailsView_PageIndexChanging ( Object src, DetailsViewPageEventArgs e ) {
// Cancel the paging operation if the DetailsView control is in edit mode.
if ( EmployeeDetailsView.CurrentMode == DetailsViewMode.Edit ) {
e.Cancel = true;
// Display an error message.
int newPage = e.NewPageIndex + 1;
MessageLabel.Text = "Please update the current record before moving to page " +
newPage.ToString ( ) + ".";
}
}
void EmployeeDetailsView_ModeChanged ( Object src, EventArgs e ) {
// Clear the message label.
MessageLabel.Text = "";
}
</script>
<script language = "VB" runat = "server">
Sub EmployeeDetailsView_PageIndexChanging ( ByVal src As Object, ByVal e As DetailsViewPageEventArgs )
' Cancel the paging operation if the DetailsView control is in edit mode.
If EmployeeDetailsView.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 moving to page " & _
newPage.ToString ( ) & "."
End If
End Sub
Sub EmployeeDetailsView_ModeChanged ( ByVal src As Object, ByVal e As EventArgs )
' Clear the message label.
MessageLabel.Text = ""
End Sub
</script> |
|
C# |
VB |
DetailsView Members AllowPaging DetailsViewPageEventArgs DetailsViewPageEventHandler