Grid Adding Row with Javascript
<p>I have Grid View and Following Code In javascript to add new row. Problem is that when i click button to add new row it adds row but It contain the previous row data also and don't saves to DB. It generates error "Invalid Number".</p>

<pre><code>&lt;script type='text/javascript' language='javascript'&gt;
        function AddNewRecord()
        {
            var grd = document.getElementById('GridView1');
            var tbod=grd.rows[0].parentNode;
            var newRow=grd.rows[grd.rows.length - 1].cloneNode(true);
            tbod.appendChild(newRow);
            return false;

        }
    &lt;/script&gt;
&lt;asp:Button ID="Button2" runat="server" Text="Add Row" OnClientClick="return AddNewRecord();"/&gt;
</code></pre>

<p>What should i do so that row should generate empty and also should saves to DB.</p>

<p>I have this code for Grid</p>

<pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" OnRowCreated="myGridView_ItemCreated"  Headerstyle-CssClass="myStyle"
                                BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="859px"&gt;
                                &lt;RowStyle BackColor="White" ForeColor="#003399" HorizontalAlign="Right" /&gt;
                                &lt;Columns&gt;
                                    &lt;asp:TemplateField HeaderText="Card No"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtCardNo" runat="server" Width="60px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Zone"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:DropDownList ID="ddlZone" runat="server" DataSourceID="SqlDataSource2"
                                                DataTextField="ZONE_DESC" DataValueField="ZONE_NO" Width="80px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                            &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
                                                ProviderName="&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;" SelectCommand='SELECT DISTINCT * FROM "MLK_00_05" order by Zone_DESC'&gt;
                                            &lt;/asp:SqlDataSource&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Vehicle No"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:DropDownList ID="ddlVeh" runat="server" DataSourceID="SqlDataSource1" DataTextField="VEHICLE_NUMBER"
                                                DataValueField="VEH_COD" Width="80px"&gt;
                                            &lt;/asp:DropDownList&gt;&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
                                                ProviderName="&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;" SelectCommand='SELECT DISTINCT VEHICLE_NUMBER, DEVICEID, VEH_COD FROM MLK_VEHICLE ORDER BY 1'&gt;
                                            &lt;/asp:SqlDataSource&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Date"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:DropDownList ID="ddlStartDate" runat="server" Width="80px" AppendDataBoundItems="True"&gt;
                                            &lt;/asp:DropDownList&gt;


                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="HH  MM"&gt;
                                        &lt;ItemTemplate&gt;
                                            &amp;nbsp;&lt;asp:DropDownList ID="ddlStartHH" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;&amp;nbsp;&lt;asp:DropDownList ID="ddlStartMM" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" Width="800px" Wrap="False" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            HH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; MM
                                        &lt;/HeaderTemplate&gt;
                                        &lt;HeaderStyle Wrap="False" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Date"&gt;
                                        &lt;ItemTemplate&gt;
                                            &amp;nbsp;&lt;asp:DropDownList ID="ddlEntryDate" runat="server" Width="80px"&gt;
                                            &lt;/asp:DropDownList&gt;

                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="hh:mm"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:DropDownList ID="ddlEntryHH" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                            &lt;asp:DropDownList ID="ddlEntryMM" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            HH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; MM
                                        &lt;/HeaderTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Date"&gt;
                                        &lt;ItemTemplate&gt;
                                            &amp;nbsp;&lt;asp:DropDownList ID="ddlGrossDate" runat="server" Width="80px"&gt;
                                            &lt;/asp:DropDownList&gt;

                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="hh:mm"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:DropDownList ID="ddlGrossHH" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                            &lt;asp:DropDownList ID="ddlGrossMM" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            HH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; MM
                                        &lt;/HeaderTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Gross Weight(kg)"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtGrossWt" runat="server" Width="60px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle HorizontalAlign="Right" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Tare Weight(kg)"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtTareWt" runat="server" Width="60px" &gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle HorizontalAlign="Right" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Net Weight(kg)"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtNetWt" runat="server" Width="60px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Rate"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtRate" runat="server" Width="60px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Date"&gt;
                                        &lt;ItemTemplate&gt;
                                            &amp;nbsp;
                                            &lt;asp:DropDownList ID="DdlTareDate" runat="server" Width="80px" &gt;
                                            &lt;/asp:DropDownList&gt;

                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="hh:mm"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:DropDownList ID="ddlTareHH" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                            &lt;asp:DropDownList ID="ddlTareMM" runat="server" Width="50px"&gt;
                                            &lt;/asp:DropDownList&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle Wrap="False" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            HH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; MM
                                        &lt;/HeaderTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="FAT(%)"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtFat" runat="server" Width="50px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="LR"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtLR" runat="server" Width="50px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="SNF(%)"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtSNF" runat="server" Width="50px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Protein(%)"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtProtein" runat="server" Width="50px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="MBRT"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtMBRT" runat="server" Width="50px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Cheese"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtCheese" runat="server" Width="50px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField HeaderText="Distance"&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:TextBox ID="txtDistance" runat="server" Width="60px"&gt;&lt;/asp:TextBox&gt;
                                        &lt;/ItemTemplate&gt;
                                        &lt;ItemStyle HorizontalAlign="Right" /&gt;
                                    &lt;/asp:TemplateField&gt;
                                &lt;/Columns&gt;
                                &lt;FooterStyle BackColor="#99CCCC" ForeColor="#003399" /&gt;
                                &lt;PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" /&gt;
                                &lt;SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /&gt;
                                &lt;HeaderStyle BackColor="CornflowerBlue" Font-Bold="False" ForeColor="White" Font-Names="Arial" Font-Size="9pt" CssClass="myStyle" /&gt;
                            &lt;/asp:GridView&gt;
</code></pre>
