zoukankan
html css js c++ java
纯脚本搞掂DataGrid表表头不动,表身滚动。(转自THIN(仁与渣))
先看效果:
孟子以前也做过这事,不过他的方法前台后台都要弄,还是VB的(^-^),好像也不支持像我的自动生成列的DataGrid,所以还是自己动手,纯脚本搞掂,其实很简单,就几行:
function
ScrollDataGrid()
{
var
tb
=
document.getElementById(
"
tbHeader
"
);
var
dg
=
document.getElementById(
"
dgSearchResult
"
);
if
(dg
!=
null
)
{
var
dv
=
document.getElementById(
"
dvBody
"
);
var
th
=
dg.rows[
0
];
for
(
var
i
=
0
; i
<
th.cells.length;i
++
)
th.cells[i].width
=
th.cells[i].clientWidth;
var
tr
=
th.cloneNode(
true
);
//
tr.applyElement(tb);
tb.createTHead();
var
tbh
=
tb.tHead;
tbh.appendChild(tr);
tr
=
tbh.rows[
0
];
var
td
=
tr.insertCell();
td.style.width
=
19
;
td.width
=
19
;
td.innerHTML
=
tr.cells[
0
].innerHTML;
th.style.display
=
'none';
if
(dg.scrollHeight
<
300
)
dv.style.height
=
dg.scrollHeight
*
1
+
2
;
}
<
table
width
="100%"
border
="0"
id
="tbHeader"
cellpadding
="4"
cellspacing
="0"
>
</
table
>
<
div
style
="OVERFLOW-Y: scroll; HEIGHT: 300px"
id
="dvBody"
>
<
asp:datagrid
id
="dgSearchResult"
style
="BORDER-COLLAPSE: collapse"
runat
="server"
Width
="100%"
CellPadding
="4"
DataKeyField
="编号"
BorderWidth
="1px"
BorderStyle
="Solid"
BorderColor
="RoyalBlue"
GridLines
="None"
>
<
SelectedItemStyle
ForeColor
="SlateGray"
></
SelectedItemStyle
>
<
ItemStyle
VerticalAlign
="Middle"
></
ItemStyle
>
<
HeaderStyle
HorizontalAlign
="Center"
></
HeaderStyle
>
<
Columns
>
<
asp:ButtonColumn
Text
="选择"
HeaderText
="<font face=webdings>6</font>"
CommandName
="Delete"
>
<
HeaderStyle
Wrap
="False"
Width
="40px"
></
HeaderStyle
>
<
ItemStyle
Wrap
="False"
HorizontalAlign
="Center"
></
ItemStyle
>
<
FooterStyle
Wrap
="False"
></
FooterStyle
>
</
asp:ButtonColumn
>
</
Columns
>
</
asp:datagrid
></
div
>
发表于 2005-05-27 17:04 THIN(仁与渣)
其实使用Style-Expression更简单
<style>
TD.lockedhead { POSITION: relative; ; TOP: expression(lockhead(this)) }
</style>
<script language="javascript">
function lockhead(cell)
{
var table=cell.parentElement.parentElement;
while(table&&table.tagName.toLowerCase()!="table")
table=table.parentElement;
var _div=table.parentElement;
return _div.scrollTop+(cell.parentElement.rowIndex)*(parseInt(table.border)+parseInt(table.cellSpacing)-1);
}
</script>
<script language="javascript">
function LockHead(table,cnt)
{
if(table&&table.rows.length>=cnt)
{
for(k=0;k<cnt;k++)
{
for(i=0;i<table.rows[k].cells.length;i++)
{
table.rows[k].cells[i].className="lockedhead";
}
}
}
}
LockHead(Form1.all.DataGrid1,1);
</script>
这个是使用CodeProject上的一个版本:
这个是css:
.DataGridFixedHeader {
position: relative;
top: expression(this.offsetParent.scrollTop);
background-color: blue
}
这个是应用:
...
<HeaderStyle Font-Bold="True" CssClass="ms-formlabel DataGridFixedHeader" BackColor="#80AFEF">
</HeaderStyle>
...
原文:
http://www.cnblogs.com/thinhunan/archive/2005/05/27/163704.html
查看全文
相关阅读:
ArrayList源码剖析
Qt线程外使用Sleep
malloc、calloc和realloc比较
C++各大名库
Qt 编译boost
VC++ 设置控件显示文本的前景色、背景色以及字体
std::map的操作:插入、修改、删除和遍历
time.h文件中包含的几个函数使用时须注意事项
赋值操作符和拷贝构造函数
virtual析构函数的作用
原文地址:https://www.cnblogs.com/dagon007/p/165356.html
最新文章
C++内存泄露及常见情况总结
文献查询
uboot
kexec相关阅读
一篇牛X的文章,先收后读
linux进程调度机制
编译告警处理:dereferencing type-punned pointer will break strict-aliasing rules
samba学习
转载:大项目实用makefile
shell基础知识
热门文章
Introduction to the 80386
大数据实践(六)--hbase集群搭建(Ubuntu)
大数据实践(五)--Zookeeper集群搭建(Ubuntu)
大数据实验(四)MapReduce编程实践(Ubuntu)
Scala开发坏境设置(IDEA)
大数据实践(三)--Hadoop集群搭建(Ubuntu)
大数据实践(二)--Hdfs常见操作及Hbase安装
大数据实践(一)--Hadoop单机搭建(Ubuntu)
Python基本语法一览
LinkedList源码剖析
Copyright © 2011-2022 走看看
<style>
TD.lockedhead { POSITION: relative; ; TOP: expression(lockhead(this)) }
</style>
<script language="javascript">
function lockhead(cell)
{
var table=cell.parentElement.parentElement;
while(table&&table.tagName.toLowerCase()!="table")
table=table.parentElement;
var _div=table.parentElement;
return _div.scrollTop+(cell.parentElement.rowIndex)*(parseInt(table.border)+parseInt(table.cellSpacing)-1);
}
</script>
<script language="javascript">
function LockHead(table,cnt)
{
if(table&&table.rows.length>=cnt)
{
for(k=0;k<cnt;k++)
{
for(i=0;i<table.rows[k].cells.length;i++)
{
table.rows[k].cells[i].className="lockedhead";
}
}
}
}
LockHead(Form1.all.DataGrid1,1);
</script>
这个是使用CodeProject上的一个版本:
这个是css:
.DataGridFixedHeader {
position: relative;
top: expression(this.offsetParent.scrollTop);
background-color: blue
}
这个是应用:
...
<HeaderStyle Font-Bold="True" CssClass="ms-formlabel DataGridFixedHeader" BackColor="#80AFEF">
</HeaderStyle>
...
原文:http://www.cnblogs.com/thinhunan/archive/2005/05/27/163704.html