Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6934569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:58:38+00:00 2026-05-27T11:58:38+00:00

I have Grid View and Following Code In javascript to add new row. Problem

  • 0

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”.

<script type='text/javascript' language='javascript'>
        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;

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

What should i do so that row should generate empty and also should saves to DB.

I have this code for Grid

<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">
                                <RowStyle BackColor="White" ForeColor="#003399" HorizontalAlign="Right" />
                                <Columns>
                                    <asp:TemplateField HeaderText="Card No">
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtCardNo" runat="server" Width="60px"></asp:TextBox>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Zone">
                                        <ItemTemplate>
                                            <asp:DropDownList ID="ddlZone" runat="server" DataSourceID="SqlDataSource2"
                                                DataTextField="ZONE_DESC" DataValueField="ZONE_NO" Width="80px">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT DISTINCT * FROM "MLK_00_05" order by Zone_DESC'>
                                            </asp:SqlDataSource>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Vehicle No">
                                        <ItemTemplate>
                                            <asp:DropDownList ID="ddlVeh" runat="server" DataSourceID="SqlDataSource1" DataTextField="VEHICLE_NUMBER"
                                                DataValueField="VEH_COD" Width="80px">
                                            </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                                ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT DISTINCT VEHICLE_NUMBER, DEVICEID, VEH_COD FROM MLK_VEHICLE ORDER BY 1'>
                                            </asp:SqlDataSource>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Date">
                                        <ItemTemplate>
                                            <asp:DropDownList ID="ddlStartDate" runat="server" Width="80px" AppendDataBoundItems="True">
                                            </asp:DropDownList>


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

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

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

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

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:58:39+00:00Added an answer on May 27, 2026 at 11:58 am

    since you are doing cloneNode(true) , it will just clone the previous row and hence have the same data as previous row. to make it empty use the .text("") with each element in row, since you have not included the html i cant write the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one grid view in my web application. I use the following code
I have the following code in a partial view; <%= Html.Grid(Model).Columns(column => { column.For(model
I have a draggable view that I have set up with the following code:
I am using vb.net code. I have grid view, please see the code below:
I have a grid view control in my application. Please see the below code.
I have a Data Grid View inside a control that is displayed in a
I have used a list view that uses a grid view in WPF. I
I have this code I want to bind data to grid view without using
I have defined a nested grid view in the following way. <asp:GridView ID=GridView1 runat=server
I have a link button in my grid view and it will be disabled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.