GridView固定表头和首列

xqsky2007 2008-10-31 11:16:51
如题:

在一个blog上
http://blog.csdn.net/Samanthaqu/archive/2007/12/04/1915667.aspx 里面介绍了固定表头和首列的详细方法,按照方法固定表头可以实现,但固定首列老是实现不了,哪位高手帮我看一下
...全文
1931 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
地道点的说:方法有很多,你不动手去亲自试一试,热心帮你的人说再多无益!前途无量。自己尝试下吧!多动手。了解了就理解了!
xiao32975472 2012-06-13
  • 打赏
  • 举报
回复
留个记号吧
hzhla 2010-12-08
  • 打赏
  • 举报
回复
我也想知道啊
tangjinzn 2008-11-03
  • 打赏
  • 举报
回复
mark标记
xqsky2007 2008-11-03
  • 打赏
  • 举报
回复
回贴是一种美德,也是展示技术水平的一种体现,
如果能正确回答我的问题我加分给他,最多只加到100,超100我另起新贴加给他.

请不要留下不相关的内容,谢了
qhdrenzhijie 2008-11-03
  • 打赏
  • 举报
回复
接分
xqsky2007 2008-11-03
  • 打赏
  • 举报
回复
9楼的方法速度太慢了,只有亲自测试过的人才知道.
11楼的方法好像是在哪里抄来的.

我刚学.NET不久,请各位大哥大姐在回贴的时候 尽量给个例子,短点就可以了,最好自已亲自测试一下代码再发贴好吗?固定表头同时能固定首列老我还是不知如何做?哪位能帮我解决一下真是万分感谢.

请不要在网上随便粘贴一些内容或是看清楚我的问题再回贴可以吗?
IMAGSE 2008-11-03
  • 打赏
  • 举报
回复
用css控制一下啊~


<style type="text/css">
<!--
body {
background: #FFF;
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
margin: 10px;
padding: 0
}

table, td, a {
color: #000;
font: normal normal 12px Verdana, Geneva, Arial, Helvetica, sans-serif
}

.td
{
nowrap:‘’true‘’;
}

div.tableContainer {
clear: both;
border: 1px solid #963;
height: 285px;
overflow: auto;
width: 100%;
}

/* WinIE 6.x needs to re-account for it‘’s scrollbar. Give it some padding */
\html div.tableContainer/* */ {
padding: 0 16px 0 0
}

/* clean up for allowing display Opera 5.x/6.x and MacIE 5.x */
html>body div.tableContainer {
height: auto;
padding: 0;
width: 740px
}

/* Reset overflow value to hidden for all non-IE browsers. */
/* Filter out Opera 5.x/6.x and MacIE 5.x */
head:first-child+body div[class].tableContainer {
height: 285px;
overflow: hidden;
width: 756px
}

/* define width of table. IE browsers only */
/* if width is set to 100%, you can remove the width */
/* property from div.tableContainer and have the div scale */
div.tableContainer table {
float: left;
width: 100%
}

/* WinIE 6.x needs to re-account for padding. Give it a negative margin */
\html div.tableContainer table/* */ {
margin: 0 -16px 0 0
}

/* define width of table. Opera 5.x/6.x and MacIE 5.x */
html>body div.tableContainer table {
float: none;
margin: 0;
width: 740px
}

/* define width of table. Add 16px to width for scrollbar. */
/* All other non-IE browsers. Filter out Opera 5.x/6.x and MacIE 5.x */
head:first-child+body div[class].tableContainer table {
width: 756px
}

/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative;
/* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */
top: expression(document.getElementById("tableContainer").scrollTop)
}


/* set THEAD element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* Filter out Opera 5.x/6.x and MacIE 5.x */
head:first-child+body thead[class].fixedHeader tr {
display: block
}

/* make the TH elements pretty */
thead.fixedHeader th {
background: #C96;
border-left: 1px solid #EB8;
border-right: 1px solid #B74;
border-top: 1px solid #EB8;
font-weight: normal;
padding: 4px 3px;
text-align: center
}

/* make the A elements pretty. makes for nice clickable headers */
thead.fixedHeader a, thead.fixedHeader a:link, thead.fixedHeader a:visited {
color: #FFF;
display: block;
text-decoration: none;
width: 100%
}

/* make the A elements pretty. makes for nice clickable headers */
/* WARNING: swapping the background on hover may cause problems in WinIE 6.x */
thead.fixedHeader a:hover {
color: #FFF;
display: block;
text-decoration: underline;
width: 100%
}

/* define the table content to be scrollable */
/* set TBODY element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto */
/* Filter out Opera 5.x/6.x and MacIE 5.x */
head:first-child+body tbody[class].scrollContent {
display: block;
height: 262px;
overflow: auto;
width: 100%
}

/* make TD elements pretty. Provide alternating classes for striping the table */
/* http://www.alistapart.com/articles/zebratables/ */
tbody.scrollContent td, tbody.scrollContent tr.normalRow td {
background: #FFF;
border-bottom: 1px solid #EEE;
border-left: 1px solid #EEE;
border-right: 1px solid #AAA;
border-top: 1px solid #AAA;
padding: 2px 3px
}

tbody.scrollContent tr.alternateRow td {
background: #EEE;
border-bottom: 1px solid #EEE;
border-left: 1px solid #EEE;
border-right: 1px solid #AAA;
border-top: 1px solid #AAA;
padding: 2px 3px
}

/* define width of TH elements: 1st, 2nd, and 3rd respectively. */
/* All other non-IE browsers. Filter out Opera 5.x/6.x and MacIE 5.x */
/* Add 16px to last TH for scrollbar padding */
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors */
head:first-child+body thead[class].fixedHeader th {
width: 200px
}

head:first-child+body thead[class].fixedHeader th + th {
width: 250px
}

head:first-child+body thead[class].fixedHeader th + th + th {
border-right: none;
padding: 4px 4px 4px 3px;
width: 316px
}

/* define width of TH elements: 1st, 2nd, and 3rd respectively. */
/* All other non-IE browsers. Filter out Opera 5.x/6.x and MacIE 5.x */
/* Add 16px to last TH for scrollbar padding */
/* http://www.w3.org/TR/REC-CSS2/selector.html#adjacent-selectors */
head:first-child+body tbody[class].scrollContent td {
width: 200px
}

head:first-child+body tbody[class].scrollContent td + td {
width: 250px
}

head:first-child+body tbody[class].scrollContent td + td + td {
border-right: none;
padding: 2px 4px 2px 3px;
width: 300px

/* expression is for WinIE 5.x only. Remove to validate and for pure CSS solution */
top: expression(document.getElementById("tableContainer").scrollTop)
}
-->
</style>
cansum396 2008-11-03
  • 打赏
  • 举报
回复
用expression固定当数据量大的时候非常慢
超人Q 2008-11-03
  • 打赏
  • 举报
回复
http://www.cnblogs.com/PLAYBOY840616/archive/2008/07/24/1249328.html
如果上面的还是不行的话,试试这个
Lonfone 2008-11-03
  • 打赏
  • 举报
回复
楼上几位的方案 试过可以的呀,楼主在哪里没处理好吧
xqsky2007 2008-11-03
  • 打赏
  • 举报
回复
好多天过去了,没人回答,自已顶一下
xqsky2007 2008-11-01
  • 打赏
  • 举报
回复
GridView固定表头和首列
固定表头可以按http://blog.csdn.net/Samanthaqu/archive/2007/12/04/1915667.aspx 里面介绍的方法做可以实现,
固定首列或某一列按1楼的做法做实现不了,
哪位高手能不能自已写个例子将详细的源码贴出来我看一下?最好具体一点。分数不够我再加啊

还有拉动向下滚动条的时候表头不动,表内的数据向下移动。当拉动向右滚动条的时候,某一列固定不动(包括有表头和表体),其它列都向右称动(包括表头和表体),这两种能不能同时做到?
gengwanshanreally 2008-10-31
  • 打赏
  • 举报
回复
顶1楼的
lee576 2008-10-31
  • 打赏
  • 举报
回复
固定首列

样式表
.fixColleft
{ z-index:120; left: expression(this.offsetParent.scrollLeft); position: relative }
.fixedHeader {
overflow: auto;}
.fixColleft
{ }

后台代码:
绑定gridview
this.GridView1.Columns[0].HeaderStyle.CssClass = "fixColleft";
this.GridView1.Columns[0].ItemStyle.CssClass = "fixColleft";
this.GridView1.DataBind();
周公 2008-10-31
  • 打赏
  • 举报
回复
asp.net夜话之八:数据绑定控件
在asp.net中所有的数据库绑定控件都是从BaseDataBoundControl这个抽象类派生的,这个抽象类定义了几个重要属性和一个重要方法:DataSource属性:指定数据绑定控件的数据来源,显示的时候程序将会从这个数据源中获取数据并显示。DataSourceID属性:指定数据绑定控件的数据源控件的ID, 显示的时候程序将会根据这个ID找到相应的数据源控件,并利用这个数据源控件中指定方法获取数据并显示。DataBind()方法:当指定了数据绑定控件的DataSource属性或者DataSourceID属性之后,再调用DataBind()方法才会显示绑定的数据。并且在使用数据源时,会首先尝试使用DataSourceID属性标识的数据源,如果没有设置DataSourceID时才会用到DataSource属性标识的数据源。也就是说DataSource和DataSourceID两个属性不能同时使用。数据绑定控件的DataSource控件属性必须是一个可以枚举的数据源,如实现了ICollection、IEnumerable或IListSource接口的类的实例。
周公 2008-10-31
  • 打赏
  • 举报
回复
如果当前的项显示样式不符合我们的要求的时候,我们可以设置项的显示样式,如下图:

设置ItemStyle就可以了。
xqsky2007 2008-10-31
  • 打赏
  • 举报
回复
1楼的结果还是不行:

<div style="height:200px;overflow:auto; width: 300px;">

……
//第一列
<HeaderStyle Width="100px" CssClass="fixColleft"/>
<ItemStyle Width="100px" CssClass="fixColleft"/>
</div>

数据记录数为100条。

显示的结果是:
能锁定第一列,其中第二、三……可以实现滚动。但第一列显示100条记录,第二、三列……显示10条。为什么会是这样子的啊?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧