来自:http://zhidao.baidu.com/question/61114429
方法一:在代码里page_load 加一段:GridView1.Attributes.Add("style", "table-layout:fixed");
方法二:给你一段样式:
<head runat="server">
<link href="css/main.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>无标题页</title>
<style type="css/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;}
.FixedTitleRow
{
position: relative;
top: expression(this.offsetParent.scrollTop);
z-index: 10;
background-color: #E6ECF0;
}
.FixedTitleColumn
{
position: relative;
left: expression(this.parentElement.offsetParent.scrollLeft);
}
.FixedDataColumn
{
position: relative;
left: expression(this.parentElement.offsetParent.parentElement.scrollLeft);
background-color: #E6ECF0;
}
div#div-gridview {}{
width: 100%;
height: 160px;
overflow: auto;
}
div#div-gridview1
{}{
width: 420px;
height: 200px;
overflow: auto;
}
div#div-gridview2
{}{
width: 420px;
height: 200px;
overflow: auto;
}
div#div-gridview3
{}{
height: 0px;
overflow: auto;
}
.fixed
{
background-color:White;
position: relative ;
top:expression(this.offsetParent.scrollTop);
left:expression(this.offsetParent.scrollLeft);
z-index:2;
}
</style>
</head>
还有这里加调用:
<asp:GridView ID="GridView1" Width="1200px" runat="server" CellPadding="4"
ForeColor="#333333" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" HorizontalAlign="Center" BorderStyle="Groove">
<Columns>
<asp:BoundField DataField="GPRS" HeaderText="GPRS" HtmlEncode="False" >
<ItemStyle Height="30px" Width="50px" />
</asp:BoundField>
......
</Columns>
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="fixed" />
</asp:GridView>
注意:在GridView设置总表的宽和高,然后在每列设置高宽,就可以了.前提条件GridView的宽和高,必须大于每列设置高宽之和