前台
<script>
function scrool()
{
var t = document.getElementById("<%=gvCheckList.ClientID%>");
var t2 = t.cloneNode(true)
for(i = t2.rows.length -1;i > 0;i--)
t2.deleteRow(i)
t.deleteRow(0)
head1.appendChild(t2)
}
window.onload = scrool
</script>
<div id="head1"></div>
<div style="height:186px;width:100%;overflow-y: scroll;">
<asp:GridView ID="GridView1" runat="server" Width="97%" >
<RowStyle Height="26px" />
<HeaderStyle BackColor="#EDEDED" Height="26px" />
</asp:GridView>
</div>
后台代码
Page_Load
this.GridView1.Attributes.Add("style", "table-layout:fixed");
---------------------------------------------------------------------------------------------------------------------
string constr = @"data source=.\mssqlserver1;database=northwind;uid=sa;pwd=123456";
northwindDataContext ctx = new northwindDataContext(constr);
var order = from o in ctx.Orders
where o.EmployeeID==4 && o.ShipCountry=="USA"
select o;
var order2 = order.Take(10);
GridView1.DataSource = order2;
GridView1.DataBind();
本文介绍了一种在ASP.NET中实现GridView表头固定而内容滚动的方法。通过前端JavaScript克隆表头并将其置于单独的div中,同时设置内容区域为滚动,确保了表头始终可见。后台加载数据时对GridView样式进行了调整。
9540

被折叠的 条评论
为什么被折叠?



