Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one help to add new row in GridView through javascript dynamically
Posted

C#
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;

        }
 
Share this answer
 
Comments
VICK 10-Jul-13 8:00am    
I know this is an old post.. But I am asking the question here. coz need help regarding above.

I am trying to use the above mentioned funciton. but it is malfunctioning.. i have added this to a button onclick event. and when i press the button it just shows the new row entered and than again vanished.... can you tell that how to rebind the gridview after row being added.???/
you can also delete the row in javascript:

C#
function delrow(rowindex)

{

var gridID=document.getElementById("<%=InjGrid.ClientID %>");

gridID.deleteRow(rowindex+1);

document.getElementById ("<%=txthidnoofrows.ClientID %>").value=gridID.rows.length-1;

return false;

}
 
Share this answer
 
Comments
Miss Maheshwari 1-Oct-13 5:18am    
how can i stop user to delete last row remaining

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900