简体   繁体   English

如何根据鼠标悬停在图像上方的位置突出显示gridview行?

[英]how to highlight a gridview row based on mouse hover location over an image?

I have a GridView that I bind in PageLoad() and I use the same data to dynamically create a timeline image that displays below the GridView. 我有一个绑定在PageLoad()中的GridView,并且我使用相同的数据来动态创建显示在GridView下面的时间轴图像。 If I get 15 rows of data (pretty typical) each row in the GridView from top to bottom will have a corresponding vertical line drawn in the timeline jpg from left to right. 如果我得到15行数据(非常典型),则GridView中的每一行从上到下将在时间线jpg中从左到右绘制一条相应的垂直线。 The graph just shows how close or far apart each event is from its neighbors. 该图仅显示了每个事件与其相邻事件有多近或远。

I do draw an id below each line in the image to help identify the corresponding row in the GridView but it's tedious to locate. 我确实在图像的每一行下方绘制了一个id,以帮助标识GridView中的相应行,但是查找起来很麻烦。 It would be awesome if I could just move the mouse across the timeline image and have the corresponding rows in the GridView get highlighted as I go. 如果我可以在时间轴图像上移动鼠标,并在我走的时候让GridView中的相应行高亮显示,那就太棒了。 I know the x-coordinates of each line because I generate the image from the same data using Bitmap, Graphics, DrawLine, etc. to make and save the jpg. 我知道每一行的x坐标,因为我使用Bitmap,Graphics,DrawLine等从相同的数据生成图像来制作和保存jpg。

Any help greatly appreciated. 任何帮助,不胜感激。

asp.net 2.0, vs2010, c#. asp.net 2.0,vs2010,c#。

*** Edited to include a screen shot of the grid and the generated timeline with the mouse hovering over the 5th element. ***编辑以包括网格的屏幕快照和鼠标悬停在第5个元素上时生成的时间轴。 Data is top-to-bottom in the grid. 数据在网格中自上而下。 Same data is left-to-right in the timeline. 时间轴中的数据从左到右。

click to see screen shot 点击查看屏幕截图

To highlight a grid vertically, you need to get index of which column you are holding your mouse on. 要垂直突出显示网格,您需要获取按住鼠标的列的索引。 And implement the style you want on each of the rows corresponding columns. 并在每行对应的列上实现所需的样式。

Is this what you were looking for? 这是您要找的东西吗?

 $(function(){ $('td').hover(function(){ var indexofelement = $(this).index() + 1; $(this).closest('table').find('tr').each(function(){ $(this).find('td:nth-child(' + indexofelement + ')').css('background','grey'); }); },function(){ var indexofelement = $(this).index() + 1; $(this).closest('table').find('tr').each(function(){ $(this).find('td:nth-child(' + indexofelement + ')').css('background','transparent'); }); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table style="width:100%"> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> <td><img height="20" src="http://www.clipartbest.com/cliparts/yik/E5x/yikE5xeiE.png"/></td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> <td><img height="20" src="http://www.clipartbest.com/cliparts/yik/E5x/yikE5xeiE.png"/></td> </tr> </table> 

Edit: If you want to highlight corresponding row; 编辑:如果要突出显示相应的行;

$(function(){
  $('img').hover(function(){
    $(this).closest('tr').css('background','grey');
  },function(){
    $(this).closest('tr').css('background','transparent');
  });
});

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

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