冻结gridview标头和SUB标头

时间:2014-09-03 07:00:06

标签: c# jquery asp.net gridview jquery-plugins

在关于冻结/固定GridView标题的SO和elesewhere中有多个问题。我目前正在使用其中一个插件用于单个标头GridView。

但它不是很优雅。因为在调用jQuery函数之后,标题列不与Data列对齐。

带圆圈的列轮廓显示“未对齐”。 enter image description here

除了未对齐的问题,还需要冻结另一个GridView的标题和子标题,如下所示。

enter image description here

现在这引起了一些担忧。

  1. 为子标题编写新的jQuery插件。 The plug-in I am currently using refers to this post.我需要大量的知识支持才能写一个新的。
  2. 创建两个不同的Gridview,一个用于标题,一个用于数据。并且会出现对齐问题(因为它是最早的设计。)所有这些网格视图都执行DML / CRUD操作。
  3. 是否可以为标题编写html代码并隐藏GridView的标题?然而,在管理与内容/数据有关的动态对齐方面也存在挑战。
  4. 鉴于这种情况和选择,我只是感到困惑的可能是成本较低(时间/努力)的方向,但具有未来更新的灵活性。还要感谢编辑当前jquery函数的任何见解,以适应单头GridView的正确对齐。

1 个答案:

答案 0 :(得分:1)

由于您已经使用了插件,因此确定使用另一个插件并不困难,但这一次应将标题宽度与数据列对齐。确保使用ItemStyle-Widthboundcolumn

TemplateField属性定义/调整列宽

链接到完成此工作的GridViewScroll Demo。从here下载插件。 关于类似问题,请参阅我的其他答案herehere

这是代码

<script type="text/javascript"      src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="gridviewScroll.min.js"></script>
<link href="GridviewScroll.css" rel="stylesheet" />

function pageLoad(sender, args) {
   gridviewScroll ();
}

function gridviewScroll() {
   gridView1 = $('#GridView1').gridviewScroll({
        width: 915,
        height: 449,
        railcolor: "#F0F0F0",
        barcolor: "#CDCDCD",
        barhovercolor: "#606060",
        bgcolor: "#F0F0F0",
        freezesize: 5,
        arrowsize: 30,
        varrowtopimg: "../../../images/arrowvt.png",
        varrowbottomimg: "../../../images/arrowvb.png",
        harrowleftimg: "../../../images/arrowhl.png",
        harrowrightimg: "../../../images/arrowhr.png",
        headerrowcount: 1,
        onScrollVertical: function (delta) {
         // store the scroll offset outside of this function in a hidden field and restore if you want to maintain vertical scroll position
        },
        onScrollHorizontal: function (delta) {
          //store the scroll offset outside of this function in a hidden field and restore if you want to maintain horizontal scroll position
        }
    });
}
相关问题