本人有一个无法显示后台c#查询数据库的 var maxRowLength = (10> myloadseach.Tables[0].Rows.length?myloadseach.Tables[0].Rows.length:10);
        for (var i = 0 ;i < maxRowLength ;i++)
        {
            var tr = document.getElementById("tblMyUploadS").rows[0].cloneNode(true);//定义一个table的行
            alert(tr);tr.children[0].className = "tdClass0";//设定这行的第一列   这个是设定css
            tr.children[0].innerText = myloadseach.Tables[0].Rows[i].FileName;//设定这行的第一列   这个是设定显示的文字
            tr.children[1].className = "tdClass1";//设定这行的第二列   这个是设定css
            tr.children[1].innerText = myloadseach.Tables[0].Rows[i].StoreName;//设定这行的第二列   这个是设定显示的文字
            tr.children[2].className = "tdClass2";//设定这行的第三列   这个是设定css
            tr.children[2].innerText = myloadseach.Tables[0].Rows[i].FileType;//设定这行的第三列   这个是设定显示的文字
            tr.children[3].className = "tdClass3";//设定这行的第四列   这个是设定css
            tr.children[3].innerText = myloadseach.Tables[0].Rows[i].UpLoadDate;//设定这行的第四列   这个是设定显示的文字
            tr.children[4].className = "tdClass4";//设定这行的第五列   这个是设定css
            tr.children[4].innerText = myloadseach.Tables[0].Rows[i].FileState;//设定这行的第五列   这个是设定显示的文字
            tr.children[5].innerHTML =  "<div class = 'dateFlag'>详细</div>";//给第六列添加一个 div
            tr.children[5].className = "tdClass5";//设定这行的第六列   这个是设定css
            document.getElementById("tblMyUploadS").appendChild(tr);//给table添加行结果问题,怀疑是前台以下代码有问题,求高手指点!

解决方案 »

  1.   

    整个函数如下,希望有高手解决
    function PageBind(pageTo)
    {//自定义分页绑定函数
        // 删除table > 1 的行
        while(document.getElementById("tblMyUploadS").rows.length > 1)
        {//table行删除,只保留第一行
            document.getElementById("tblMyUploadS").deleteRow(1);
        }
        // 根据页数和条件,查询数据************ 特别注意,这要根据页数去查询******************
        var textname = document.getElementById("txtMyUpload").value;
        var library = document.getElementById("ddlStore").value;
        var mytimefrom = document.getElementById("txtDateFrom").value;
        var mytimeto = document.getElementById("txtDateTo").value;
        var myloadseach=Page_Show_MyUpload.CheckMyLoad(textname,library,mytimefrom,mytimeto,pageTo).value;
        // 查询错误处理
        if(myloadseach == null || myloadseach.Tables[0].Rows.length == 0)
         {
             document.getElementById("trMsg").style.display = "inline";
             document.getElementById("txtMyUpload").focus();
         }
        else
        {
            var maxRowLength = (10> myloadseach.Tables[0].Rows.length?myloadseach.Tables[0].Rows.length:10);
            for (var i = 0 ;i < maxRowLength ;i++)
            {
                var tr = document.getElementById("tblMyUploadS").rows[0].cloneNode(true);//定义一个table的行
                alert(tr);tr.children[0].className = "tdClass0";//设定这行的第一列   这个是设定css
                tr.children[0].innerText = myloadseach.Tables[0].Rows[i].FileName;//设定这行的第一列   这个是设定显示的文字
                tr.children[1].className = "tdClass1";//设定这行的第二列   这个是设定css
                tr.children[1].innerText = myloadseach.Tables[0].Rows[i].StoreName;//设定这行的第二列   这个是设定显示的文字
                tr.children[2].className = "tdClass2";//设定这行的第三列   这个是设定css
                tr.children[2].innerText = myloadseach.Tables[0].Rows[i].FileType;//设定这行的第三列   这个是设定显示的文字
                tr.children[3].className = "tdClass3";//设定这行的第四列   这个是设定css
                tr.children[3].innerText = myloadseach.Tables[0].Rows[i].UpLoadDate;//设定这行的第四列   这个是设定显示的文字
                tr.children[4].className = "tdClass4";//设定这行的第五列   这个是设定css
                tr.children[4].innerText = myloadseach.Tables[0].Rows[i].FileState;//设定这行的第五列   这个是设定显示的文字
                tr.children[5].innerHTML =  "<div class = 'dateFlag'>详细</div>";//给第六列添加一个 div
                tr.children[5].className = "tdClass5";//设定这行的第六列   这个是设定css
                document.getElementById("tblMyUploadS").appendChild(tr);//给table添加行
            }
        }
    }
      

  2.   

    public DataSet CheckMyLoad(string fileName, string fileLibrary, string fileMytimefrom, string fileMytimeto,int pageNum)//与数据库比较,返回比较结果
        {
             int pageNumAll = pageNum * 10;
            int pageNumNotin = (pageNum - 1) * 10;
            string strSql = " select TOP " +
                pageNumAll +
                "  TB_FileInfo.FileName,TB_Store.StoreName,TB_FileInfo.FileType,TB_FileInfo.UpLoadDate,TB_FileInfo.FileState " +
                " from TB_FileInfo left join TB_Store on TB_FileInfo.StoreID = TB_Store.StoreID where TB_FileInfo.FileName='" + 
                fileName +
                "'  AND TB_FileInfo.StoreID='" + 
                fileLibrary + 
                "' AND TB_FileInfo.UpLoadDate >='" + 
                fileMytimefrom + 
                "' AND TB_FileInfo.UpLoadDate <= '" + 
                fileMytimeto + 
                "' AND TB_FileInfo.FileName NOT IN ( select top " +
                pageNumNotin +
                " TB_FileInfo.FileName from TB_FileInfo left join TB_Store on TB_FileInfo.StoreID = TB_Store.StoreID where TB_FileInfo.FileName='" + 
                fileName +
                "'  AND TB_FileInfo.StoreID='" +
                fileLibrary +
                "' AND TB_FileInfo.UpLoadDate >='" +
                fileMytimefrom +
                "' AND TB_FileInfo.UpLoadDate <= '" +
                fileMytimeto + 
                "')"; //SQL语句
           
            return dl.RunSql_ds(strSql, "connStrFile");
        }
    以上是后台查询函数,单步跟着没有发现问题
      

  3.   

    LZ向Table插入新的行不能直接向Table对象进行插入,要找到tbody才行,因此把
    document.getElementById("tblMyUploadS").appendChild(tr);//给table添加行
    改为
    document.getElementById("tblMyUploadS").getElementsByTagName("tbody")[0].appendChild(tr);//给table添加行
      

  4.   

    或者这样也可以 
    document.getElementById("tblMyUploadS").children[0].appendChild(tr);//给table添加行 
      

  5.   

    非常感谢ouyang3857116 ,在你的帮助下问题已经解决!