当前位置:编程学习 > C#/ASP.NET >>

Repeater一行多条记录的解决方案

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>填充表格数据</title>
<script type="text/javascript">
<!--
function fillTableData(cols,height)
{
    var trData=document.getElementById("tab_data");
    var tabObj=document.getElementById("dataTable");
    if(trData!=null)
    {
        //设定表头列的colspan
        tabObj.rows[0].cells[0].colSpan=cols;
        //设置列高度
        height=height||30;
        //填充数据
        var tds=trData.cells;
        var newtr=null;
        var times=0;
        while(tds.length>0)
        {
            if(times%cols==0)
            {
                newtr=tabObj.insertRow(trData.rowIndex);
                newtr.style.backgroundColor="#ffffff";
                newtr.style.height=parseInt(height)+"px";
            }
            tds[0].style.width=(100/cols).toFixed(1)+"%";
            newtr.appendChild(tds[0]);
            times++;
        }
        //补全最后一行的td
        for(var i=newtr.cells.length;i<cols;i++)
        {
            var newtd=newtr.insertCell(-1);
            newtd.innerHTML=" ";
            newtd.style.width=100/cols+"%";
        }
    }
    trData.parentNode.removeChild(trData);
}
window.onload=function()
{
    fillTableData(4,30);
};
//-->
</script>
</head>
<body>
<table id="dataTable"style="width:98%; border-width:0px; background-color:#cccccc;" cellpadding="0" cellspacing="1">
<tr>
    <th style="text-align:center;background-color:#f1f5fe;height:30px">时间</th>
</tr>
<tr id="tab_data" style="display:none">
    <td title="2000-01"><a href="#">2000-01</a></td>
    <td title="2000-02"><a href="#">2000-02</a></td>
    <td title="2000-03"><a href="#">2000-03</a></td>
    <td title="2000-04"><a href="#">2000-04</a></td>
    <td title="2000-05"><a href="#">2000-05</a></td>
    <td title="2000-06"><a href="#">2000-06</a></td>
    <td title="2000-07"><a href="#">2000-07</a></td>
    <td title="2000-08"><a href="#">2000-08</a></td>
    <td title="2000-09"><a href="#">2000-09</a></td>
    <td title="2000-10"><a href="#">2000-10</a></td>
    <td title="2000-11"><a href="#">2000-11</a></td>
    <td title="2000-12"><a href="#">2000-12</a></td>
    <td title="2001-01"><a href="#">2001-01</a></td>
</tr>
</table>
</body>
</html>

补充:asp.net教程,.Net开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,