<script language="javascript">
        
//初始化表头,生成双层表头    
        window.onload = function()
        {
            
var obj = document.getElementById("DataGrid1");            
            
if(obj != undefined)
            {
                
var row=obj.insertRow(0);
                row.className 
= "headStyle";
                
var Cell1 = row.insertCell();
                Cell1.innerText 
= "单位";
                Cell1.rowSpan 
= 3;
                
                
var Cell2 = row.insertCell();
                Cell2.innerText 
= "在职";
                Cell2.colSpan
=4;                
                
                
var Cell3 = row.insertCell();
                Cell3.innerText 
= "退休";
                Cell3.colSpan 
= 4;
                
                
var Cell4 = row.insertCell();
                Cell4.innerText 
= "合计";
                Cell4.colSpan 
= 2;    
                Cell4.rowSpan
=2;    
                
                
var row1=obj.insertRow(1);
                row1.className 
= "headStyle";
                
                
                
var Cell5 = row1.insertCell();    
                Cell5.innerText 
= "<=45";    
                Cell5.colSpan 
= 2;        
                
var Cell6 = row1.insertCell();    
                Cell6.innerText 
= ">45";    
                Cell6.colSpan 
= 2;    
                
                
var Cell7 = row1.insertCell();    
                Cell7.innerText 
= "<=65";
                Cell7.colSpan 
= 2;        
                
var Cell8 = row1.insertCell();    
                Cell8.innerText 
= ">65";    
                Cell8.colSpan 
= 2;        
                
                obj.rows[
2].deleteCell(0);    
                
            }
        }
        
</script>

datagrid的绑定列的表头可以正常写,然后用Javascript画出需要的多层表头.这段代码的最重要的一步就是对是否存在datagrid的判定,因为如果后台代码不是开始load页面的时候就绑定datagrid并显示的话,这段代码会报错.
posted on 2007-02-06 14:55  xiazhaoxia  阅读(413)  评论(0编辑  收藏  举报