ASP.Net ListView 回发速度慢,列表视图中有大量数据

发布于 2024-11-25 10:17:31 字数 285 浏览 6 评论 0原文

我的页面上有一个列表视图,可以显示 10,000 行或更多行。

页面顶部有一个简单的“客户”下拉菜单,可以自动回发以更改数据过滤器。我一直在尝试优化这个例程,我注意到大部分时间都花在将 ViewState 从客户端传输到服务器上。

我已将 EnableViewState="false" 添加到 ListView 控件,但它并没有改变它。我查看了 Fiddler 中的请求,如果屏幕上的客户有 50 行,则请求内容长度很短 - 如果他们有 10,000 行或其他内容,则请求内容长度很大。

有人有解决办法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花浅忆 2024-12-02 10:17:31

发生这种情况是因为数据绑定控件(包括列表视图)会将其数据源存储到视图状态中。因此视图状态会很大,导致页面大小膨胀。

解决方案之一是禁用列表视图的视图状态并在每次页面回发时绑定它。

更好的解决方案是进行数据存储侧分页,即如果仅显示 50 行,则仅从数据库中获取 50 行。这在 ASP.NET 中通常称为自定义分页,您可以找到适合您的数据访问技术的自定义分页的多个示例。例如,

使用实体框架和自定义分页。 ObjectDataSource: http://geekswithblogs .net/Frez/articles/using-the-entity-framework-and-the-objectdatasource-custom-paging.aspx

您可以使用 SQL Server 排名函数在存储过程: http://msdn.microsoft.com/en-us/library/ bb445504.aspx

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文