gridview表头固定的问题 30

给gridview加了个垂直的滚动条想让表头固定这个已经实现了是我想要的效果后来发现整个网页在浏览器的位置偏左就像让整个网页居中显示于是在网上找了一下给body加了几个属... 给gridview加了个垂直的滚动条 想让表头固定 这个已经实现了 是我想要的效果 后来发现整个网页在浏览器的位置偏左 就像让整个网页居中显示 于是在网上找了一下 给body加了几个属性<margin:0; padding:0; text-align:center>
但是这样做的效果是整个网页居中了 唯有表头水平位置没变 还是偏左 这就与gridview错位了 这个问题怎么解决啊 望高手指教 下面是部分代码:

.Freezing
{
position:relative ;
table-layout:fixed;
top:expression(this.scrollTop);

z-index: 10;
}
.Freezing th{text-overflow:ellipsis;overflow:hidden;white-space: nowrap;padding:2px;}

<tr>
<td>
<div style=" overflow-y: scroll; height: 360px; width:100%;" >

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
CellPadding="4" Font-Size="10pt" ForeColor="#333333" GridLines="None"
OnDataBinding="GridView1_DataBinding"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="100%" >
<Columns> <asp:BoundField DataField="BookName" HeaderText="图书名称" SortExpression="ID" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="Author" HeaderText="作者" SortExpression="BookName"></asp:BoundField>
<asp:BoundField DataField="Publish" HeaderText="出版社" SortExpression="Publish"></asp:BoundField>
<asp:BoundField DataField="pTime" HeaderText="出版日期" SortExpression="pTime"></asp:BoundField>
<asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN"></asp:BoundField>
</Columns>
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" CssClass="Freezing" Wrap="false" />
</asp:GridView>
</div>

</td>
</tr>
下面的“我是楼主代码”就是我 已经把全部代码贴出来了 谢谢啦
展开
 我来答
我是楼主代码
2009-08-12
知道答主
回答量:1
采纳率:0%
帮助的人:0
展开全部
我是楼主 下面是全部代码
<%@ Page Language="C#" AutoEventWireup="true" AspCompat="true" CodeFile="~/index/Default.aspx.cs" Inherits="index_Default" Title="图书信息"%>
<!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>图书信息</title>
<style type="text/css">

.mstheme-bannertxt
{
height: 209px;
width: 605px;
margin-left: 0px;
margin-bottom: 0px;
}

.Freezing
{
position:relative ;
table-layout:fixed;
top:expression(this.scrollTop);

z-index: 10;
}
.Freezing th{text-overflow:ellipsis;overflow:hidden;white-space: nowrap;padding:2px;}

</style>
</head>
<body style="height: 1000px;">
<form id="form1" runat="server">
<div>
<table style="width: 955px; background-image: url('../images/11.jpg'); height: 995px;">
<tr style="background-image: url('../images/7.jpg');">
<td style="height: 141px;">
</td>
</tr>
<tr style="background-image: url(../images/2.jpg); height: 30px" valign="middle">
<td>
<table style="width: 100%">
<tr>
<td style="width: 600px">

</td>

</tr>
</table>
</td>
</tr>

<tr align="center" valign="top">
<td >
<table>
<tr valign="top">

<td style="width: 800px;" align="center">
<%--<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>--%>

<table width="800">
<tr>
<td style=" height: 272px; font-weight: bold; font-size: 60px; font-family: 隶书; background-image: url('../images/5.jpg');
color:#cc9933;" >

<marquee class="mstheme-bannertxt">吾生也有涯 而知也无涯</marquee>
</td>
</tr>
<tr align="center" style="height:500px;">
<td style=" width: 638px; height: 350px; background-image:url('../images/6.jpg');">
<table style="width: 550px; height: 372px; margin:0; padding:0; text-align:center; ">
<tr align="right">
<td valign="middle" >
<asp:DropDownList AutoPostBack="false" ID="DropDownList1" runat="server" Width="90px"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Font-Size="10pt">
<asp:ListItem>全部</asp:ListItem>
<asp:ListItem>按名称</asp:ListItem>
<asp:ListItem>按作者</asp:ListItem>
<asp:ListItem>按出版社</asp:ListItem>
<asp:ListItem>按出版日期</asp:ListItem>
<asp:ListItem>按ISBN</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="false" Font-Size="10pt" Width="90px"
OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="查找" OnClick="Button1_Click" Font-Size="10pt" /></td>
</tr>
<tr>
<td>
<div style=" overflow-y: scroll; height: 360px; " >

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
EmptyDataText="There are no data records to display."
CellPadding="4" Font-Size="10pt" ForeColor="#333333" GridLines="None"
OnDataBinding="GridView1_DataBinding"
onselectedindexchanged="GridView1_SelectedIndexChanged"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:BoundField DataField="BookName" HeaderText="图书名称" SortExpression="ID" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="Author" HeaderText="作者" SortExpression="BookName"></asp:BoundField>
<asp:BoundField DataField="Publish" HeaderText="出版社" SortExpression="Publish"></asp:BoundField>
<asp:BoundField DataField="pTime" HeaderText="出版日期" SortExpression="pTime"></asp:BoundField>
<asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN"></asp:BoundField>
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" CssClass="ms-formlabel DataGridFixedHeader" />
<SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" Font-Bold="True" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" CssClass="Freezing" Wrap="false" />
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BookInfoConnectionString %>"
SelectCommand="SELECT * FROM [Books]"></asp:SqlDataSource>
</div>

</td>
</tr>
</table>
<tr style="height: 100px;">
<td></td>
</tr>

</td>
</tr>
</table>

<%--<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>--%>
</td>

</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式