System.Web.UI.WebControls Namespace DetailsView Class
.NET Framework version 2.0
Updates the current record in the data source.
[ VB ]
Overridable Public Sub UpdateItem ( _
ByVal causesValidation As Boolean _
)
[ C# ]
public virtual void UpdateItem (
bool causesValidation
);
[ C++ ]
public: virtual void UpdateItem (
bool* causesValidation
);
[ JScript ]
public function UpdateItem (
causesValidation : Boolean
);
- causesValidation
- true to perform page validation when the method is called; otherwise false.
Exception Type |
Condition |
HttpException |
This method is called when the DetailsView control is not in edit mode.
-or-
The DataSourceView object associated with the DetailsView control is null. |
When the DetailsView control is in edit mode, use the UpdateItem method to programmatically edit the current record in the data source. This method is commonly used when you need to edit the current record from outside of the DetailsView control, such as from a different control on the page.
NOTE: The DetailsView control must be in edit mode when this method is called; otherwise, an HttpException is thrown.
To specify whether page validation is performed before the update operation, use the causesValidation parameter. Calling this method also raises the ItemUpdated and ItemUpdating events.
The following example demonstrates how to use the UpdateItem method to programmatically edit the current record in a DetailsView control in the data source.
<%@ Page language = "C#" %>
<script runat = "server">
void InsertButton_Click ( Object src, EventArgs e ) {
try {
EmployeeDetailsView.UpdateItem ( true );
MessageLabel.Text = "";
} catch ( HttpException ex ) {
MessageLabel.Text = "The DetailsView control must be in edit mode to update a record.";
}
}
void CancelButton_Click ( Object src, EventArgs e ) {
// Return the DetailsView control to read-only mode.
EmployeeDetailsView.ChangeMode ( DetailsViewMode.ReadOnly );
MessageLabel.Text = "";
}
</script>
<%@ Page language = "VB" %>
<script runat = "server">
Sub InsertButton_Click ( ByVal src As Object, ByVal e As EventArgs )
Try
EmployeeDetailsView.UpdateItem ( True )
MessageLabel.Text = ""
Catch ex As HttpException
MessageLabel.Text = "The DetailsView control must be in edit mode to update a record."
End Try
End Sub
Sub CancelButton_Click ( ByVal src As Object, ByVal e As EventArgs )
' Return the DetailsView control to read-only mode.
EmployeeDetailsView.ChangeMode ( DetailsViewMode.ReadOnly )
MessageLabel.Text = ""
End Sub
</script> |
|
C# |
VB |
DetailsView Members DeleteItem InsertItem