简体   繁体   English

无法在ASP.Net 3.5中同时滚动2个网格

[英]Unable to Scroll 2 Grids simultaneously in ASP.Net 3.5

I am working on a web application using visual studio 2008 (ASP.Net 3.5 with C#). 我正在使用Visual Studio 2008(带有C#的ASP.Net 3.5)开发Web应用程序。 I have added two GridViews of System.Web.UI.WebControls.GridView type. 我添加了两个System.Web.UI.WebControls.GridView类型的GridView。 Now I want that when I scroll the GridView1 horizontally, the GridView2 also scrolls along with it. 现在,我希望在水平滚动GridView1时,GridView2也随之滚动。 I have tried many solutions but whenever I tried to use the solution code, error occurred that 'does not contain a definition for Scroll/HorizontalScrollBar etc'. 我尝试了许多解决方案,但是每当我尝试使用解决方案代码时,都会发生错误,“其中不包含Scroll / Horizo​​ntalScrollBar等的定义”。 Even there is no GridView event for scrolling through which I can solve my problem. 甚至没有用于浏览的GridView事件也可以解决我的问题。

If anybody has the solution then please let me know. 如果有人有解决方案,请告诉我。 I will be very pleased because I am trying to solve this problem from last 2 days. 我将非常高兴,因为我试图从最近的2天开始解决此问题。

You can put your grids in two divs named left and right styling them with overflow:scroll; 您可以将网格放置在两个div中,分别命名为leftright分别使用overflow:scroll;样式化它们overflow:scroll; .

<div id="left">
    ...grid1 here
</div>

<div id="right">
    ...grid2 here
</div>

Then you can use the following jQuery script to synchronize scrolling events: 然后,您可以使用以下jQuery脚本来同步滚动事件:

$(window).load(function(){
    $('#right').on('scroll', function () {
        $('#left').scrollLeft($(this).scrollLeft());
    });
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM