纯脚本搞掂DataGrid表表头不动,表身滚动

先看效果:

孟子以前也做过这事,不过他的方法前台后台都要弄,还是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 ="&lt;font face=webdings&gt;6&lt;/font&gt;"  CommandName ="Delete" >
                                                        
< HeaderStyle  Wrap ="False"  Width ="40px" ></ HeaderStyle >
                                                        
< ItemStyle  Wrap ="False"  HorizontalAlign ="Center" ></ ItemStyle >
                                                        
< FooterStyle  Wrap ="False" ></ FooterStyle >
                                                    
</ asp:ButtonColumn >
                                                
</ Columns >
                                            
</ asp:datagrid ></ div >

 

 

http://thinhunan.cnblogs.com/archive/2005/05/27/163704.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值