asp.net.ph

DetailsView.InsertItem Method

System.Web.UI.WebControls Namespace   DetailsView Class


.NET Framework version 2.0

Inserts the current record in the data source.

[ VB ]
Overridable Public Sub InsertItem ( _
   ByVal causesValidation As Boolean _
)

[ C# ]
public virtual void InsertItem (
   bool causesValidation
);

[ C++ ]
public: virtual void InsertItem (
   bool* causesValidation
);

[ JScript ]
public function InsertItem (
   causesValidation : Boolean
);

Parameters

causesValidation
true to perform page validation when the method is called; otherwise, false.

Exceptions


Exception Type Condition
HttpException This method is called when the DetailsView control is not in insert mode.

-or-

The DataSourceView object associated with the DetailsView control is null.


Remarks

When the DetailsView control is in insert mode, use the InsertItem method to programmatically insert the current record in the data source. This method is commonly used when you need to insert 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 insert mode when this method is called; otherwise, an HttpException is thrown.

To specify whether page validation is performed before the insert operation, use the causesValidation parameter. Calling this method also raises the ItemInserted and ItemInserting events.

Example

The following example demonstrates how to use the InsertItem method to programmatically insert 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.InsertItem ( true );
         MessageLabel.Text = "";
      } catch ( HttpException ex ) {
         MessageLabel.Text = "The DetailsView control must be in insert mode to insert a record.";
      }
   }

   void CancelButton_Click ( Object src, EventArgs e ) {
      // Return the DetailsView control to read-only mode.
      EmployeeDetailsView.ChangeMode ( DetailsViewMode.ReadOnly );
      MessageLabel.Text = "";
   }
</script>
  C# VB

See Also

DetailsView Members   DeleteItem   UpdateItem Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph