System.Web.UI.WebControls Namespace DetailsView Class
.NET Framework version 2.0
Returns the current data-entry mode of the DetailsView control.
Script |
[ DetailsViewMode var = ] DetailsView.CurrentMode |
The property is read only with a default value of ReadOnly.
Use the CurrentMode property to determine whether the DetailsView control is in edit, insert, or read-only mode. The following table lists the different mode values.
Mode |
Description |
DetailsViewMode.Edit |
The DetailsView control is in edit mode, which allows the user to update the values of a record. |
DetailsViewMode.Insert |
The DetailsView control is in insert mode, which allows the user to add a new record to the data source. |
DetailsView.ReadOnly |
The DetailsView control is in read-only mode, which is the normal display mode. |
This value is normally set automatically by the DetailsView control when the New, Update, Insert, Delete, or Cancel command button is clicked. When the DetailsView control changes modes in response to an action, the events in the following table are raised. This allows you to create a custom event handler that performs the appropriate routine when the event occurs.
Event |
Description |
ModeChanged |
Occurs when the DetailsView control changes modes, but after the mode changes. This event is commonly used to perform a task whenever the DetailsView control changes modes. |
ModeChanging |
Occurs when the DetailsView control changes modes, but before the mode changes. This event is commonly used to cancel the mode change. |
NOTE: These events are not raised when you change the mode programmatically by using the ChangeMode method.
The following example demonstrates how to use the CurrentMode property to determine whether the DetailsView control is in edit, insert, or read-only mode. If the user attempts to navigate to another record while the DetailsView control is in edit more, the paging operation is canceled.
<%@ Page language = "C#" %>
<script runat = "server">
void fvEmployee_OnPageIndexChanging ( Object src, DetailsViewPageEventArgs e ) {
// Cancel the paging operation if the user attempts to navigate
// to another record while the DetailsView control is in edit mode.
if ( fvEmployee.CurrentMode == DetailsViewMode.Edit ) {
e.Cancel = true;
MessageLabel.Text =
"Please complete the update operation before navigating to another record.";
}
}
void fvEmployee_OnModeChanged ( Object src, EventArgs e ) {
// Clear the message label.
MessageLabel.Text = "";
}
</script>
<%@ Page language = "VB" %>
<script runat = "server">
Sub fvEmployee_OnPageIndexChanging ( ByVal src As Object, ByVal e As DetailsViewPageEventArgs )
' Cancel the paging operation if the user attempts to navigate
' to another record while the DetailsView control is in edit mode.
If fvEmployee.CurrentMode = DetailsViewMode.Edit Then
e.Cancel = True
MessageLabel.Text = _
"Please complete the update operation before navigating to another record."
End If
End Sub
Sub fvEmployee_OnModeChanged ( ByVal src As Object, ByVal e As EventArgs )
' Clear the message label.
MessageLabel.Text = ""
End Sub
</script> |
|
C# |
VB |
DetailsView Members DetailsViewMode Enumeration ChangeMode DefaultMode