I have a listview on my page that can display 10,000 or more rows.
There's a simple 'customer' drop down on the top of the page that does an auto-postback to change the data filter. I've been trying to optimize this routine and I noticed that the majority of the time is spent transferring the ViewState from the client to server.
I've added EnableViewState="false" to the ListView control but it doesn't change it. I've looked at the request in Fiddler and if the customer on screen has say 50 rows, the request content length is low - if they have 10,000 or something it's huge.
Anyone have a fix?
This is happening because data-bound control (including list view) would store their data-source into the view-state. So view-state will be large cause page size bloat.
One of the solution is to disable the view-state for list-view and bind it every time page posts back.
Even better solution is to do data store side paging i.e. if you are showing only 50 rows then fetch only 50 rows from the database. This is typically referred as custom paging in ASP.NET and you can find several examples for custom paging for your data access technology. For example,
custom paging uing Entity Framework & ObjectDataSource: http://geekswithblogs.net/Frez/articles/using-the-entity-framework-and-the-objectdatasource-custom-paging.aspx
You can use SQL Server ranking functions to do paging in a stored procedure: http://msdn.microsoft.com/en-us/library/bb445504.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With