<style> 
 .Freezing 
  { 
    position:relative ; 
    table-layout:fixed;
    top:expression(this.offsetParent.scrollTop);   
    z-index: 10;
  } 
 .Freezing th{text-overflow:ellipsis;overflow:hidden;white-space: nowrap;padding:2px;}
</style> 
    <div style="overflow-y: scroll; height:200px; width:auto; width:217px; " id="dvBody">    
        
          <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CellPadding="5" Width="200px">
            <Columns>
            
              <asp:TemplateField HeaderText="序号">
                  <ItemTemplate>  
                      <%# Container.DataItemIndex + 1%>  
                    </ItemTemplate>  
              </asp:TemplateField>
                            
              <asp:BoundField DataField="username" HeaderText="UserName" />
              <asp:BoundField DataField="realname" HeaderText="RealName" />
            </Columns>
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="Freezing"/>
        </asp:GridView>
    
    
    </div>
演示 下载