GridView固定表头

转帖|其它|编辑:郝浩|2008-09-27 14:01:08.000|阅读 3646 次

概述:GridView固定表头

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"> 
    <title>GridView固定表头</title>
    <style type="text/css"> 
        .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>  
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div style="overflow-y: scroll; height: 200px;width:500px" id="dvBody"> 
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="10" ForeColor="#333333" PageSize="3">  
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> 
            <Columns> 
                <asp:BoundField DataField="ID" HeaderText="用户ID" ReadOnly="True" />
                <asp:BoundField DataField="Name" HeaderText="用户姓名" /> 
                <asp:BoundField DataField="Sex" HeaderText="性别" /> 
                <asp:BoundField DataField="Birthday" HeaderText="生日" DataFormatString="{0:yyyy年M月dd日}" HtmlEncode="false" />
                <asp:BoundField DataField="Salary" HeaderText="薪水" />
                <asp:BoundField DataField="Address" HeaderText="家庭住址" /> 
                <asp:BoundField DataField="PostCode" HeaderText="邮政编码" />
            </Columns> 
            <RowStyle ForeColor="#000066" /> 
            <SelectedRowStyle BackColor="#669999" Font-Bold=value>"True" ForeColor="White" /> 
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> 
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="Freezing" /> 
        </asp:GridView>
    </div> 
    </form> 
</body> 
</html>

用法:CSS设如上的样式,HeaderStyle加CssClass="Freezing,套住GridView的Div设置高度宽度 <div style="overflow-y: scroll; height: 200px;width:200px" >


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:DIY部落

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP