2

I have an EntityDataSource bound to many filters used by gridview data, I want to have access to the entities that was selected be the EntityDataSource to be able to export them in xml for example, how can I do that?

kaiz.net
  • 1,984
  • 3
  • 23
  • 31
Andron
  • 223
  • 1
  • 3
  • 14

1 Answers1

3

You get access to result of query executed in EntityDataSource by handling its Selected event and accessing Results of EntityDataSourceSelectedEventArgs.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Actually you are getting access to only first portion of the response, can I somehow get access to whole data not only for current page? – Andron Mar 05 '12 at 12:28
  • If you have paging enabled you will get access only to the selected page because nothing more is returned from the query. It would require you to turning paging off (or modify it in `Selecting` event) but then you must somehow disconnect data source from UI component to avoid loading all data to UI. You can also get access to query in `QueryCreated` even but I expect it will already have paging applied. – Ladislav Mrnka Mar 05 '12 at 12:48
  • 1
    For those using this, this works for me: `var x = e.Results.Cast().ToList();` ... replacing `EntityClass` with your own. – PeterX May 12 '14 at 08:46
  • I tried this and am getting this error: Unable to cast object of type 'System.Data.Objects.MaterializedDataRecord' to type 'myEntityClass'. – Dov Miller Feb 19 '17 at 11:11