先看效果:

纯脚本搞定DataGrid表表头不动,表身滚动

  孟子以前也做过这事,不过他的方法前台后台都要弄,还是VB的(^-^),好像也不支持像我的自动生成列的DataGrid,所以还是自己动手,纯脚本搞掂,其实很简单,就几行:

function ScrollDataGrid()
    {
      var tb = document.getElementById("tbHeader");
      var dg = document.getElementById("dgSearchResult");
      if(dg!= null)
      {  
        var dv = document.getElementById("dvBody");
        var th = dg.rows[0];
        for(var i = 0 ; i < th.cells.length;i++)
          th.cells[i].width = th.cells[i].clientWidth;
        var tr = th.cloneNode(true);
        //tr.applyElement(tb);
        tb.createTHead();
        var tbh = tb.tHead;
        tbh.appendChild(tr);
        tr = tbh.rows[0];
        var td = tr.insertCell();
        td.style.width = 19;
        td.width = 19;
        td.innerHTML = tr.cells[0].innerHTML;
        th.style.display = 'none';
        if(dg.scrollHeight < 300 )
          dv.style.height = dg.scrollHeight * 1 + 2;
      }
        <table width="100%" border="0" >                      </asp:datagrid></div>

相关文章:

  • 2021-08-22
  • 2022-02-25
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
猜你喜欢
  • 2021-12-06
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
相关资源
相似解决方案