I'm fixing up a website which makes extensive use of the DevExpress ASPxGridView control to search against tables on a SQL Server. The results are then paged and parsed. Some of the search results can be fairly large and I suspect in those cases the built in pager for the ASPxGridView with the native SqlDataSource is prohibitively slow. On one query I observed the network traffic between the SQL Server and the IIS Server to be 1.5 GB over the span of just under a minute. Running the same query with an ORDER BY (SELECT NULL) OFFSET x ROWS FETCH NEXT y ROWS ONLY took a split second. Taking advantage of this SQL side paging on the control is another matter.
It seems my limitations and trade offs are the following:
The DevExpress ASPxGridView built in pager can't have the number of items explicitly set.
The independent DevExpress ASPxPager doesn't support client side events.
Replacing the SqlDataSource with LinqServerModeSource or XpoDataSource still has to parse the entire result set from the SQL Server to get the full count and will probably suffer the same performance issues.
I would like suggestions if any of following are possible solutions:
Is there any way to force the DevExpress ASPxGridView built in pager to use an external count?
Is there any way to wrap the DevExpress ASPxPager with say an Asp.Net UpdatePanel or DevExpress ASPxCallbackPanel to support client side events?
Can the LinqServerModeSource or XpoDataSource collect results from the SQL query as the ASPxGridView is paged with the total count provided by other means?
As mentioned here, it is possible to use SQL server side paging with ASPxGridView and ObjectDataSource by setting the ASPxGridView.DataSourceForceStandardPaging = true. DevExpress links to this example application on GitHub which is a bit broken, but easy to fix.
It works but, as they say:
[...] it is not possible to filter the ObjectDataSource datasource when the ASPxGridView.DataSourceForceStandardPaging is used.
Currently I'm trying to cheat the ASPxGridView by not setting DataSourceForceStandardPaging, but still use server side paging with ObjectDataSource: Perhaps it is possible to insert dummy rows into the result set in ObjectDatasource's SelectMethod, which then makes ASPxGridView "think" that is has retrieved all rows from the database, so that the pager can count the correct total rows number.
But I am not yet done with it... most probably the SubstituteFilterand CustomColumnSort events must then be handled to prevent the ASPxGridView from filtering and sorting the dummy records out.
Related
We have developed Asp.net web application. and we are using asp.net gridview to display the records and edit.
here we have 5000 rows and 23 columns in single grid. it is taking long time for binding. our client refuse the pagination option. how to make the binding faster with 5000 to 7000 records.
Please Advise.
Thanks
Mayil.M
Where is your data come from? Is it database or other external resource?
You can use caching so you don't load the whole dataset from the external resource but from the memory. Please note this solution will not work if your data changes often.
Another approach would be to use some kind of partial loading mechanism using for example Ajax. This will however require changing approach as I am not sure the grid view control supports this. You would have to create custom control and then make sequential requests (using for example Ajax) for smaller chunks (eg. 200 records) of data and display them. Eventually you will have complete set but the data will be available faster.
Finally you can combine both, to make it even faster.
You should implement your own paging mechanism. The problem is that DataBind retrieves all 7000 records (although only i.e. 20 is displayed/rendered). Create for example a stored procedure that will fetch only selected range of records (if you are on Page 2 you need to display only record id > 20 and <= 40 - considering that your pagesize is 20). Use SQL server CTE to get the row number (on SQL Server side) and features like BETWEEN. This stored procedure would return only those records which you really need to. Then change your grid view to get the data from this stored procedure.
You can load data on scroll like facebook wall.
In My Database I Have 10000000 Records. In GridView First I Am Showing First 10 Records. In Order To See the Next Records User Need to Click Page Numbers ( 1,2,3,------10000). But As I'm Retrieving 10 Records for The First Time GridView Paging is not Showing.
Is There Any Way To Show Paging In ASP.NET GridView Statically ?
For so many records, I won't recommend Paging. You can show Top 20 recently added records and provide options to filter out records. A user can enter keywords. ReQuery and ReBind the GridView with this new result set.
You might also consider using PetaPoco, a Micro-ORM, which will help you fetch paged result.
With so many records, you really need to take into account the exact queries being run to pull back the data.
There are numerous ways of doing data paging ( http://beyondrelational.com/modules/2/blogs/28/posts/10434/sql-server-server-side-paging-with-rownumber-function.aspx ). However, the "best" way is dependent on the exact version of SQL Server you are running.
Essentially, the solutions boil down to you passing a page number and number of records per page through some type of query. Usually a stored procedure as the query can be quite messy.
Once there, you have an option. Either send the total record count back as an OUT parameter in your query and the result set back normally, or you send the total record count back as a column. There are definitely efficiency concerns with both options as one way requires the query to be run twice and the other requires an extra column of data which increases network traffic.
Once you have that solved then you can figure out exactly how you want the UI to work.
I did a task which geting more than 2 millions record from sqlserver and populate them in Asp.net GridView.
The problem is that, query taking more than 2 minutes in getting record while my query is now fully optimized.
when i move from one page to another by pagination it take again same time and hit server.
so i need a solution where its not take time during page movement or get only 50 or 100 record in each request.
Thanks,
Nauman
Use paging in GridView - check this link
Also adjust display property like display header with available visible cells to load the grid faster.
Its even better if you bind the grid data using jQuery and not from server side.
Use this link to get started
Instead of using GridView you can use repeater or even jQuery templates also with custom paging. that'll be even more fast.
if you are fetching 1000 records and displaying just 50 using pagination, this is really a waste. better to display 50 records each time, this would be much faster. go through the following link:Custom Paging in ASP.Net GridView using SQL Server Stored Procedure
it's problem on sqlserver...
optimization the data base,separate the database and the table
DevExpress aspxgridview with LinqServerModeDataSource or alternative for fast filtering and sorting
We are trying to produce a read-only grid of results where speed is the prioirity. Currently using a gridview control with some customization for select row on click and fixed header / footers. Data access is from either objectdatasource or code binding from our business layer, database is SQL Server 2008.
The plan is to buy 3rd party controls for the gridview and have been looking at DevExpress aspxgridview. We would like to be able to add attributes to the gridview data, filter and very quickly bind the grid and have looked at the LinqServerModeDataSource, This would probably mean having another data access technology in the solution but would be happy with this for any read-only queries where we can easily do joins and sorts quickly at the database but use the n-tier BLL / DAL / DTOs for any insert / update / deletes.
Does anyone have any thoughts on this plan. Would the LinqServerModeDataSource and the aspxgridview be quick to display data and give the options to pile on filters (joins / exists queries) to the table we are binding to or is there a better way of doing this.
(I assume we would need to edit the linq query in LinqServerModeDataSource OnSelecting) Would prefer not to write any custom ajax or html and let a custom control do this.
When ASPxGridView is bound to a LinqServerModeDataSource all data related operations are performed on the DB server. In this situation, the dataSource sends many requests to the DB server but all these requests are light, i.e. they should be executed fast and do not result in large data passed to the web server. Also, I would like to warn you that the grid working in server mode has some limitations and they are described in our help:
Server-side Data Management
Finally, I think that ASPxGridView working in server mode is very fast and you eventually should give it a try. However, a server mode should be used only when an underlying DataSource returns a lot of data. Otherwise, it is better to use the "classic" binding mode when all is managed on the web server.
Update
I will try to explain at which point a server mode is needed. By default, all grid controls (standard, our ...) fetch all data to the web server from the DB server and than manage it. For example, sort. If a data size is small and a connection between DB and web servers is fast, this operation is done fairly fast and a server mode is not needed. From my point of view, 5k records is not large data and thus the ASPxGridView's code should work with it effectively and fast. However, if there are a lot of records which should be processed on the web server, for example, 100k the picture is different. Obviously, fetching 100k to the web server and transferring them via net can be slow. Also, the DB server is optimized to work with such data much more better and it should manage this data, for example, sort them faster. In this case, it is more profitable to propagate this work to the DB server and gain the performance.
So, the main criteria which must be used to decide whether or not to use a server mode is the following:
the number of records passed from the DB server to the web server and the time needed to manage it.
Hope, this helps.
I know in asp.net 1.0 the grid display controls would pull all the data in, and then provide paging but the paging was done in memory.
Are there any smarter controls that provide paging where they only pull the data relevent to current page being displayed?
ie. select 10 rows for the current page, instead of doing a select of ALL the rows in the table.
I believe that the object data sources have properties to pass paging parameters, which can be used to then get the subset of data that you require.
Some samples here.