如何在不向上滚动的情况下绑定DataGrid组件的数据?
我有一个 DataGrid 组件,我想每 5 秒更新一次。当行被添加到这个 DataGrid 时,我注意到每次更新都会导致它将滚动条位置重置到顶部。如何才能将滚动条保持在之前的位置?
I have a DataGrid component that I would like to update every 5 seconds. As rows are being added to this DataGrid I noticed that every update causes it to reset the scroll bar position to the top. How can I manage to keep the scroll bar at its previous position?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建一个变量来存储最后的滚动位置并使用它。
大致如下:
这不是最好的代码,但它说明了这一点,每当有人完成滚动事件时,您都会将最后一个位置存储在变量中,并在添加新数据后立即使用它来恢复滚动位置。
make a variable to store your last scroll position and use that.
roughly something like:
It's not the best code, but it illustrates the point, whenever someone finishes the scroll event, you store last position in a variable and you use that to restore the scroll position right after you've added new data.
我基于 这篇文章。看起来效果很好。
I wrote a little extension class to
DataGrid
based on this article. It seems to work great.我还没有测试过这段代码,但它应该可以工作:
I haven't tested this code, but it should work:
这些可能会有所帮助:
异步回发后保持滚动位置
在回发时维持滚动位置< /a> (进一步向下滚动以阅读此内容)
These might help:
Maintain Scroll Position after Asynchronous Postback
Maintaining Scroll Position on Postback (Scroll further down to read this)