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?
You get access to result of query executed in EntityDataSource by handling its Selected event and accessing Results of EntityDataSourceSelectedEventArgs.
Related
How can I configure a gridview and datasource on a page to only execute the query if the user clicks a button?
The datasource will return over 1 million records and the page will be accessed by a lot of people at the same time. One potential way to achieve this is to set up the datasource with a connection string and query, but do not assign it to the grid view. Then assign the gridview to the datasource and call databind when it is needed.
In this scenario, will the datasource run the query on page load? Or will it only run the query when I call databind on the gridview?
The short answer in no, the datasource select statement is only called when bind method is called.
see details http://msdn.microsoft.com/en-us/library/dz12d98w%28v=vs.80%29.aspx
http://msdn.microsoft.com/en-us/library/w1kdt8w2%28v=vs.100%29.aspx
Transcribe-->
The data source control executes the commands when its corresponding Select, Update, Delete, or Insert method is called. The Select method is called automatically when you call the DataBind method of the page or of a control bound to the data source control. You can also call any of the four methods explicitly when you want the data source control to execute a command. Some controls, such as the GridView control, can call the methods automatically, without requiring that you call the methods or that you explicitly call the DataBind method.
Datasource will not run the query on page load on your case. Write your gridview binding code on click event, then it will run the query only after click the button. If you have millons of records on your DB, its not fair way to bind the whole records on the gridview. Fetch only the particular page records from DB and bind it to gridview. It will increase your performance and wil take very less time.
I need help choosing between Telerik RadGrid and DevExpress ASPxGridView for Asp.Net based on unique filtering requirements. The data lives in denormalized Vax files. All data access is via Sql Server stored procedures calling ODBC Connx queries to the flat files. Stored procedure parameters are used to filter the data. Without any filter thousand of records are returned.
I've successfully displayed all records on two test ASP.net pages, one with DevExpress ASPxGridVIew and the other with Telerik's RadGrid. In code I databind each grid to the stored procedure that returns over 26,000 rows. The sproc is called via an Entity Framework function import that fills an IEnumerable<Customer> which becomes the datasource of each respective grid. I'm able to use the filter features of both grids and they seem to work nicely.
My problem is that before the grid filter is applied all of the thousands of rows are returned from the stored procedure. I'd like to intercept the grid's filter parameters and apply them to my stored procedure parameters. That way far fewer records will be accessed.
Can this be done with either 3rd party grid and if so how?
Thanks in advance.
It seems it can be achieved using a RadFilter to the RadGrid. One example here.
But in general, looks like you'd need to add a handler to ItemCommand, and perform the appropriate filter based on the CommandName, for example. You could then just rebind the data.
The Rad Filter will also allow you to use it without being directly tied to another control or datasource. The filter has an option to extract a filter expression in many different forms (linq provider is one of them). You can then apply that expression to your datasource. We are doing something similar. We have a page where we dynamically create the rad filter with the types of fields and filter options. The user then uses the rad filter UI to create the filter based on the desired fields, then we extract a filter expression we can apply to a datatable that is created on the page that shows the data.
Here is the code for extracting the filter expression from the filter:
var provider = new RadFilterSqlQueryProvider();
provider.ProcessGroup(myRadFilter.RootGroup);
var sqlFilterExpression = provider.Result;
I have a database and I've created a DBML Linq-to-SQL file to represent this database. I've created a new aspx page and dropped a linqdatasource and a formview control onto it. When I configure the linqdatasource it gives me the choice only to select * from one table...but I want to pull from multiple tables. e.g. I have tables like simple_person, simple_address, simple_phone, and I want to pull from all of them. How can I accomplish this?
Use a custom query
http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx
See: Using the <asp:LinqDataSource> Selecting Event
I'm using a detailsview control to update a record, however in this particular case there's only one field that can be changed out of a many. The update method for my object takes all fields as parameters. When the detailsview's updating method fires, the values for the readonly fields (those rendered as a Label) are not available in the e.NewValues collection.
I'm currently grabbing a reference to the object when the detailsview is databound (in the objectdatasource selected event handler), storing it in session and manually adding entries to the e.NewValues collection when updating fires. It works but seems kind of heavy handed.
So, is there a better way to get the read only values back into my update method? Or is there a better way of doing this altogether?
There should be an OriginalValues collection too, which may have the collection of readonly values... can you verifiy that?
HTH.
Is it possible to use a SQL query that returns XML, in order to bind a TreeView control to SQL data? In other words, I would like to set up a query that presents table data as hieracrhical XML, and bind this XML to the TreeView.
Are you assuming to bind TreeView to XmlDataSource (XmlHierarchicalDataSourceView)?
You can implement your own IHierarchicalDataSource and HierarchicalDataSourceView for that. I thinks this solution would be better than returning XML from DB.