Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SqlDataSource.Inserted Event

Occurs when an insert operation has completed.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

member Inserted : IEvent<SqlDataSourceStatusEventHandler,
    SqlDataSourceStatusEventArgs>

Handle the Inserted event to examine the values of output parameters after an insert operation has completed. The output parameters are available from the SqlDataSourceStatusEventArgs object that is associated with the event.

For more information about handling events, see Consuming Events.

The following code example demonstrates how to retrieve data from Microsoft SQL Server and display it in a GridView control and how to use a DetailsView control to see details of a selected row in the GridView and as a form to insert new records.

NoteNote

This example shows how to use declarative syntax for data access. For information about how to access data by using code instead of markup, see Accessing Data in Visual Studio.

Initially, the data is displayed in the GridView control, and the selected row of the GridView is also displayed in the DetailsView control. The GridView and DetailsView controls use different data source controls; the one that is associated with the DetailsView has the FilterExpression and FilterParameters properties, which ensures that the selected row of the GridView is displayed.

If you click the automatically generated Insert button of the DetailsView control, the DetailsView shows a different user interface, which is used to insert a new record. The example uses a stored procedure to insert records and returns the primary key of the inserted row. If you insert a record, the DetailsView automatically populates the InsertParameters collection with values from the bound columns and calls the Insert method. The DetailsView can infer the correct parameters from any BoundField object and a parameter for the TemplateField object when the ASP.NET two-way data-binding syntax is used. In this example, an additional parameter is added in the OnInserting event handler to handle the primary key that is returned by the stored procedure.

Finally, after data is inserted into the database by the DetailsView control, the OnInserted event handler is called to handle the Inserted event, the value of the primary key of the inserted row is displayed, and the DataBind method of the GridView control is called explicitly to refresh the data.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
Show:
© 2015 Microsoft