EntityDataSource.Selected 事件

定義

發生於查詢已執行之後。Occurs after a query has been executed.

public:
 event EventHandler<System::Web::UI::WebControls::EntityDataSourceSelectedEventArgs ^> ^ Selected;
public event EventHandler<System.Web.UI.WebControls.EntityDataSourceSelectedEventArgs> Selected;
member this.Selected : EventHandler<System.Web.UI.WebControls.EntityDataSourceSelectedEventArgs> 
Public Custom Event Selected As EventHandler(Of EntityDataSourceSelectedEventArgs) 

事件類型

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.

Results物件的屬性 EntityDataSourceSelectedEventArgs 包含 IEnumerable 從查詢傳回之物件的。The Results property of the EntityDataSourceSelectedEventArgs object contains an IEnumerable of objects that are returned from the query. 處理 Selected 事件,以在中取出並儲存傳回的實體 ViewStateHandle the Selected event to retrieve and store returned entities in the ViewState. 請執行此動作,以保存頁面上的物件變更。Do this to persist object changes on the page.

TotalRowCount物件的屬性會 EntityDataSourceSelectedEventArgs 顯示所有頁面中的物件總數,而不論資料繫結控制項為了分頁而傳遞的值為何。The TotalRowCount property 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. TotalRowCount 只有在資料繫結控制項需要時才會抓取,例如,如果已啟用分頁功能。TotalRowCount is only retrieved if the data-bound control needs it, such as if paging is enabled.

如果在準備或執行查詢時,發生錯誤,則 Selected 會引發事件,物件的 Exception 屬性 EntityDataSourceSelectedEventArgs 會設定為傳回的 Exception ,而 Results 屬性會設定為 nullIf 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. 如果您在事件處理常式中處理例外狀況 Selected ,請將 ExceptionHandled 屬性設定為 trueIf you handle the exception in the Selected event handler, set the ExceptionHandled property to true. 這可避免再次引發例外狀況。This prevents the exception from being raised again. 當您為屬性指定的值時 false ExceptionHandled ,會 EntityDataSource 重新引發例外狀況。When you specify a value of false for the ExceptionHandled property, the EntityDataSource re-raises the exception.

適用於