GridView实现滚动条

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 
 3 <html xmlns="http://www.w3.org/1999/xhtml" >
 4 <head runat="server">
 5     <title>GridView固定表头 清清月儿http://blog.csdn.net/21aspnet </title>
 6         <style>
 7 .Freezing
 8    {
 9    
10    position:relative ;
11    table-layout:fixed;
12    top:expression(this.offsetParent.scrollTop);  
13    z-index: 10;
14    }
15 
16 .Freezing th{text-overflow:ellipsis;overflow:hidden;white-space: nowrap;padding:2px;}
17 </style>
18 </head>
19 <body style="font-size=12px">
20     <form id="form1" runat="server">
21     <div style="overflow-y: scroll; height: 200px;300px" id="dvBody">
22                    <asp:GridView ID="GridView1" runat="server"    AutoGenerateColumns="False" CellPadding="3" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
23                         OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Font-Size="12px" OnRowCreated="GridView1_RowCreated"  >
24                         <FooterStyle BackColor="White" ForeColor="#000066" />
25                         <Columns>
26                             <asp:BoundField DataField="身份证号码" HeaderText="编号" ReadOnly="True" />
27                             <asp:BoundField DataField="邮政编码" HeaderText="邮政编码" SortExpression="邮政编码" />
28                             <asp:BoundField DataField="家庭住址" HeaderText="家庭住址"  />
29                             <asp:BoundField DataField="姓名" HeaderText="姓名"  />
30                            
31                         </Columns>
32                         <RowStyle ForeColor="#000066" />
33                         <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
34                         <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left"  CssClass="ms-formlabel DataGridFixedHeader"/>
35                         <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="Freezing"/>
36                     </asp:GridView>
37         </div>
38 
39     </form>
40 </body>
41 </html>
42 
43 用法:CSS设如上的样式,HeaderStyle加CssClass="Freezing,套住GridView的Div设置高度宽度 <div style="overflow-y: scroll; height: 200px;200px" >

原文地址:https://www.cnblogs.com/feb9903/p/709275.html