冻结asp.net网格视图列

前端之家收集整理的这篇文章主要介绍了冻结asp.net网格视图列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在asp.net网格视图中冻结最初的2 -3最左列?因此,当水平滚动时,始终显示已冻结的初始2 – 3列.

任何答案?

解决方法

是的,似乎有可能用一些css魔法,虽然这附带溢出的警告:滚动可能不是100%便携式(我已经在IE 8/9和Chrome FWIW上测试过)

看看这个jsFiddle here

我用来生成GridView的ASPX如下所示.

请注意,css类分别固定和滚动固定和滚动列(应用于标题和项目)

但真正的工作是在CSS中完成的.请特别注意,您需要使列宽正确,以适应左侧固定的td / th.

ASPX

  1. <div id="scrolledGridView">
  2. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  3. <Columns>
  4. <asp:BoundField DataField="ID" HeaderText="Col 1">
  5. <HeaderStyle CssClass="pinned col1"></HeaderStyle>
  6. <ItemStyle CssClass="pinned col1"></ItemStyle>
  7. </asp:BoundField>
  8. <asp:BoundField DataField="Name" HeaderText="Column 2">
  9. <HeaderStyle CssClass="pinned col2"></HeaderStyle>
  10. <ItemStyle CssClass="pinned col2"></ItemStyle>
  11. </asp:BoundField>
  12. <asp:BoundField DataField="Description" HeaderText="Column 3">
  13. <HeaderStyle CssClass="scrolled"></HeaderStyle>
  14. <ItemStyle CssClass="scrolled"></ItemStyle>
  15. </asp:BoundField>
  16. <asp:BoundField DataField="Cost" HeaderText="Column 4">
  17. <HeaderStyle CssClass="scrolled"></HeaderStyle>
  18. <ItemStyle CssClass="scrolled"></ItemStyle>
  19. </asp:BoundField>
  20. </Columns>
  21. </asp:GridView>

CSS

  1. #scrolledGridView
  2. {
  3. overflow-x: scroll;
  4. text-align: left;
  5. width: 400px; /* i.e. too small for all the columns */
  6. }
  7.  
  8. .pinned
  9. {
  10. position: fixed; /* i.e. not scrolled */
  11. background-color: White; /* prevent the scrolled columns showing through */
  12. z-index: 100; /* keep the pinned on top of the scrollables */
  13. }
  14. .scrolled
  15. {
  16. position: relative;
  17. left: 150px; /* i.e. col1 Width + col2 width */
  18. overflow: hidden;
  19. white-space: nowrap;
  20. min-width: 500px; /* set your real column widths here */
  21. }
  22. .col1
  23. {
  24. left: 0px;
  25. width: 50px;
  26. }
  27. .col2
  28. {
  29. left: 50px; /* i.e. col1 Width */
  30. width: 100px;
  31. }

猜你在找的asp.Net相关文章