代码:
<!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 runat="server">
<title>GridView固定表头 清清月儿http://blog.csdn.net/21aspnet </title>
<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>
</head>
<body style="font-size=12px">
<form id="form1" runat="server">
<div style="overflow-y: scroll; height: 200px;width:300px" id="dvBody">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Font-Size="12px" OnRowCreated="GridView1_RowCreated" >
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="身份证号码" HeaderText="编号" ReadOnly="True" />
<asp:BoundField DataField="邮政编码" HeaderText="邮政编码" SortExpression="邮政编码" />
<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" />
<asp:BoundField DataField="姓名" HeaderText="姓名" />
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" CssClass="ms-formlabel DataGridFixedHeader"/>
<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" >
<!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 runat="server">
<title>GridView固定表头 清清月儿http://blog.csdn.net/21aspnet </title>
<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>
</head>
<body style="font-size=12px">
<form id="form1" runat="server">
<div style="overflow-y: scroll; height: 200px;width:300px" id="dvBody">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Font-Size="12px" OnRowCreated="GridView1_RowCreated" >
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="身份证号码" HeaderText="编号" ReadOnly="True" />
<asp:BoundField DataField="邮政编码" HeaderText="邮政编码" SortExpression="邮政编码" />
<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" />
<asp:BoundField DataField="姓名" HeaderText="姓名" />
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" CssClass="ms-formlabel DataGridFixedHeader"/>
<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" >
解决方案 »
- 字符串操作
- GridView能做出这个效果吗?
- .Net 2.0发送邮件到邮件服务器出错(Windows Server 2003),错误见内
- (vb)我下了个ASP.NET的整站程序,碰到的第一个错误,关于WEB.CONFIG的,请大家指教,谢谢!
- 我不相信没有人做过对一个或两个listbox绑定的数据作批量删除,与添加功能,请参考代码,请指出有什么不对,谢谢!
- [求助]利用dataset来修改数据库的内容,为什么不能成功?请教高手!!
- 求助,连接测试服务器出错,请求解释!!
- 想引用System.Web,发现System中没有Web了,怎么办啊??
- 从早等到晚,就为解决这一个问题!!
- 求救!!!关于在线考试系统……
- 为什么我用DIV布局在IE下正常,换到FIREFOX下就变样了呢?
- 关于DataSet 和 web.config的极难的问题
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging"
OnSorting="GridView1_Sorting" PageSize="5" AutoGenerateColumns="False" Width="2000px"
BorderColor="SeaShell" BorderStyle="Solid" BorderWidth="1px" CellPadding="2"
ForeColor="Black" GridLines="Vertical">
<Columns>
<asp:BoundField DataField="经销商编码" HeaderText="经销商编码" ReadOnly="True" SortExpression="经销商编码">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="经销商名称" HeaderText="经销商名称" ReadOnly="True" SortExpression="经销商名称">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="经销商类型" HeaderText="经销商类型" ReadOnly="True" SortExpression="经销商类型">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="月份" HeaderText="月份" ReadOnly="True" SortExpression="月份">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="B2C每周拜访指标" HeaderText="B2C每周拜访指标" ReadOnly="True" SortExpression="B2C每周拜访指标">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="SPANCO状态跟踪" HeaderText="SPANCO状态跟踪" ReadOnly="True" SortExpression="SPANCO状态跟踪">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="销售代表应收历史" HeaderText="销售代表应收历史" ReadOnly="True" SortExpression="销售代表应收历史">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="销售代表应收帐龄历史" HeaderText="销售代表应收帐龄历史" ReadOnly="True" SortExpression="销售代表应收帐龄历史">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="经销商每月生意指标" HeaderText="经销商每月生意指标" ReadOnly="True" SortExpression="经销商每月生意指标">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="SPANCO状态汇总" HeaderText="SPANCO状态汇总" ReadOnly="True" SortExpression="SPANCO状态汇总">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="每周KPI指标" HeaderText="每周KPI指标" ReadOnly="True" SortExpression="每周KPI指标">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="销售数据" HeaderText="销售数据" ReadOnly="True" SortExpression="销售数据">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="进销存数据" HeaderText="进销存数据" ReadOnly="True" SortExpression="进销存数据">
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="库存数据" HeaderText="库存数据" ReadOnly="True" SortExpression="库存数据">
<ItemStyle Width="150px" />
</asp:BoundField>
</Columns>
<PagerSettings Visible="False" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
Width="1px" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle CssClass="Freezing" BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Panel>
里面上面是列头
下面是又一个div(用于上下滚动),里面套Repeater显示的数据