职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 671|回复: 1

gridview表头固定的问题

[复制链接]
林妹妹 发表于 2009-8-18 11:18 | 显示全部楼层 |阅读模式
给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=\"ublish\" HeaderText=\"出版社\" SortExpression=\"ublish\"></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-8-18 11:18 | 显示全部楼层

gridview表头固定的问题

我是楼主 下面是全部代码
<%@ 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(&#39;../images/11.jpg&#39;); height: 995px;">
<tr style="background-image: url(&#39;../images/7.jpg&#39;);">
<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(&#39;../images/5.jpg&#39;);
color:#cc9933;">

<marquee class="mstheme-bannertxt">吾生也有涯 而知也无涯</marquee>
</td>
</tr>
<tr align="center" style="height:500px;">
<td style=" width: 638px; height: 350px; background-image:url(&#39;../images/6.jpg&#39;);">
<table style="width: 550px; height: 372px; margin:0; padding:0; text-align:center; ">
<tr align="right">
<td valign="middle" >
<aspropDownList AutoPostBack="false" ID="DropDownList1" runat="server" Width="90px"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Font-Size="10pt">
<aspistItem>全部</aspistItem>
<aspistItem>按名称</aspistItem>
<aspistItem>按作者</aspistItem>
<aspistItem>按出版社</aspistItem>
<aspistItem>按出版日期</aspistItem>
<asp:ListItem>按ISBN</asp:ListItem>
</aspropDownList>
<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="ublish" HeaderText="出版社" SortExpression="ublish"></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" />
<agerStyle 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>
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-4-27 16:38 , Processed in 0.139351 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表