i<sourceTb.rows.length;  错在这句,吧html代码也贴出来

解决方案 »

  1.   

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <div style="text-align: center">
            &nbsp;<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Label"></asp:Label>
            <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Label"></asp:Label>
            <strong>合同承接明细表测量</strong><br />
                    <br />
                    <asp:GridView ID="GridView1" runat="server" Font-Bold="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False" Width="531px" CellPadding="4" ForeColor="#333333" GridLines="None"
                     OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit" AllowPaging="True" DataKeyNames="Contract_Num">
                        <Columns>
                            <asp:BoundField DataField="Num" HeaderText="序号" />
                            <asp:BoundField DataField="Contract_Num" HeaderText="合同编号" />
                            <asp:BoundField DataField="Contract_Date" HeaderText="签订日期" />
                            <asp:BoundField DataField="Contract_Sum" HeaderText="合同金额" />
                            <asp:BoundField DataField="Contract_Person" HeaderText="经办人" />
                            <asp:BoundField DataField="Res" HeaderText="备注" />
                        </Columns>
                        <EmptyDataTemplate>
                            <table id="tbHeader" style="width: 497px; height: 23px">
                                <tr>
                                    <td style="width: 120px; height: 27px">
                                        序号</td>
                                    <td style="width: 181px; height: 27px">
                                        合同编号</td>
                                    <td style="width: 212px; height: 27px">
                                        签订日期</td>
                                    <td style="width: 544px; height: 27px; text-align: center;">
                                        合同金额</td>
                                    <td style="width: 173px; height: 27px">
                                        经办人</td>
                                    <td style="width: 259px; height: 27px">
                                        备注</td>
                                    <td style="width: 212px; height: 27px">
                                    </td>
                                </tr>
                            </table>
                        </EmptyDataTemplate>
                        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#E3EAEB" />
                            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                            <HeaderStyle BackColor="#5BA5C8" Font-Bold="True" ForeColor="White" />
                            <EditRowStyle BackColor="#7C6F57" />
                            <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
            <br />
                    <table style="width: 413px" id="tbForm">
                        <tr>
                            <td style="width: 20px; height: 26px;">
                                <asp:TextBox ID="TextBox1" runat="server" Width="70px"></asp:TextBox></td>
                            <td style="width: 99px; height: 26px;">
                                <asp:TextBox ID="TextBox2" runat="server" Width="70px"></asp:TextBox></td>
                            <td style="width: 129px; height: 26px;">
                                <asp:TextBox ID="TextBox3" runat="server" Width="70px"></asp:TextBox></td>
                            <td style="width: 99px; height: 26px;">
                                <asp:TextBox ID="TextBox4" runat="server" Width="92px"></asp:TextBox></td>
                            <td style="width: 81px; height: 26px;">
                                <asp:TextBox ID="TextBox5" runat="server" Width="70px"></asp:TextBox></td>
                            <td style="width: 36px; height: 26px;">
                                <asp:TextBox ID="TextBox6" runat="server" Width="70px"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td style="width: 20px">
                            </td>
                            <td style="width: 99px">
                            </td>
                            <td style="width: 129px">
                            </td>
                            <td style="width: 99px">
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox4"
                                    Display="Dynamic" ErrorMessage="请输入数字" Font-Size="10pt" ValidationExpression="^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$|^-?\d+$"
                                    Width="67px"></asp:RegularExpressionValidator></td>
                            <td style="width: 81px">
                            </td>
                            <td style="width: 36px">
                            </td>
                        </tr>
                    </table>
            <br />
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Font-Size="12pt">添加</asp:LinkButton><br />
            <br /><span style="font-size: 12pt">&nbsp; &nbsp;<a href="../measuredval.aspx">返回</a></span>
            &nbsp;</div>
         <script language="javascript">
            function MergeTable(source,dest)
        {
            var row;
            var cell;
            var sourceTb = document.all(source);
            var destTb = document.all(dest);
            for (var i=0; i<sourceTb.rows.length; i++)
            {
                 row = document.createElement("TR");
                for (var j=0; j<sourceTb.rows(i).cells.length; j++)
                {
                    cell = document.createElement("TD");
                    row.appendChild(cell);
                    //复制对象
                    for(k=0;k<sourceTb.rows(i).cells(j).all.length;k++)
                        cell.appendChild(sourceTb.rows(i).cells(j).all.item(k));
                }
                destTb.tBodies(0).appendChild(row);
            }
            for (var i=sourceTb.rows.length-1; i>=0; i--)
            {
                sourceTb.deleteRow(i)
            }
        }//    function ChangeTableLayout()
    //    {
    //        if(document.all('tbHeader') == null)
    //            MergeTable('tbForm','GridView1');
    //        else
    //            MergeTable('tbForm','tbHeader');
    //    }
        function ChangeTableLayout()
        {
            if(document.all('tbHeader') == null){
             if(document.all('tbForm') != null&&document.all('GridView1') != null)
                MergeTable('tbForm','GridView1');
                else
                 alert("tbForm或GridView1不存在!");
            }else{
             if(document.all('tbForm') != null)
                MergeTable('tbForm','tbHeader');
                else
                alert("tbForm不存在!");
            }
        }    ChangeTableLayout();
       </script>
    </asp:Content>