EntityDataSource.Selected Event


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Occurs after a query has been executed.

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

public event EventHandler<EntityDataSourceSelectedEventArgs> Selected

The Selected event is raised after a query has been executed and data has been returned. It is also raised if an error occurred during query preparation or execution.

The Results property of the EntityDataSourceSelectedEventArgs object contains an IEnumerable of objects that are returned from the query. Handle the Selected event to retrieve and store returned entities in the ViewState. Do this to persist object changes on the page.

The TotalRowCountproperty of the EntityDataSourceSelectedEventArgs object shows the total number of objects in all pages, regardless of the values passed by the data-bound control for paging. TotalRowCountis only retrieved if the data-bound control needs it, such as if paging is enabled.

If an error occurs when the query is prepared or executed, the Selected event is raised, the Exception property of the EntityDataSourceSelectedEventArgs object is set to the returned Exception, and the Results property is set to null. If you handle the exception in the Selected event handler, set the ExceptionHandled property to true. This prevents the exception from being raised again. When you specify a value of false for the ExceptionHandled property, the EntityDataSource re-raises the exception.

.NET Framework
Available since 3.5
Return to top