gridview固定表头

1、在<head>里面加上

<script type="text/javascript">

function s()

{

 var t = document.getElementById("<%=GridView1.ClientID%>");

 var t2 = t.cloneNode(true)

 for(i = t2.rows.length -1;i > 0;i--)

 t2.deleteRow(i) 

 t.deleteRow(0) 

 a.appendChild(t2)

}

window.onload = s

</script>

2、在“GridView”前后加上
<div id="a"></div>
<div style="overflow-y: scroll; height: 120px">
<asp:GridView>
</asp:GridView>
</div>

3、在2的前面加上

就行了。

4、注意问题:要让表头和表身的各自段对应,则要设置gridview的编辑列,进入设置每列的headerstyle和Itemstyle的width属性,并且两个值要统一。

原文地址:https://www.cnblogs.com/maoyu417/p/1132313.html