locked
adding rows in Gridview from javascript RRS feed

  • Question

  • Hi everybody ,

    I am facing a problem while going to add a new row from javascript in gridview.

    is there any body who has done this. As i have script for deleting the rows from

    javascript.

    function delrow(rowindex)

    {

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

    gridID.deleteRow(rowindex+1);

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

    return false;

    }

    sandesh khare

    Monday, February 26, 2007 7:27 AM

Answers

  •  

    Don't do this in JavaScript. Rather use a serverside call to add rows. If you want to do it asynchronously, don't use the GridView.

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, October 26, 2010 1:44 PM

All replies

  •  

    Hi Sandesh,

     

    Even i have the same issue. If you have found solution for this problem then please reply back.

     

     

    Thanks and Regards,

    Shailesh

    Wednesday, September 5, 2007 10:34 AM
  • If you use "System.Web.UI.WebControls.GridView" class, you can use "CreateRow()" method to add a row.

    If you don't... sorry I don't know.

    Thursday, September 6, 2007 5:13 AM
  • hi sandesh here is the solution to add new row in gridview

    function AddRow(<%=gridview.clientid%>')

    {

    var gridview = document.getElementById(gridview);

    var tr = document.createElement("tr");

    var cell1 = document.createElement("td");

    var celln = document.createElement("td");

    cell1.innerHTML = '...';

    celln.innerHTML = '....';

    tr.appendChild(cell1);

    tr.appendChild(celln);

    datagrid.firstChild.appendChild(tr);

    }

    Tuesday, January 29, 2008 8:49 AM
  •  

    Create New Row in gridview using java script

    function AddNewRecord1()

    {

     

     

    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;

     

    }

    • Proposed as answer by Tom de Koning Tuesday, October 26, 2010 1:44 PM
    Monday, October 25, 2010 11:57 AM
  •  

    Don't do this in JavaScript. Rather use a serverside call to add rows. If you want to do it asynchronously, don't use the GridView.

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, October 26, 2010 1:44 PM
  • yes dear frd

    U are absulty right.

    I do it its add row and colo daynamically very fine but not acciable in server side.

    i am not able to access any control in server side

    for(i=0;i<gridview.row.count;i++)

    {

    inside i find my control and access its value

    }

    i am unable to go inside the loop  and also not access the control and its value.

    please help me out

    How can resove this adding gridview row daynamically  and accesiablein server side.

     

    Friday, October 29, 2010 11:16 AM
  • This did exactly this - added an exact match of the row cloned.

    Now I need to initialize its values - I don't want the values of the row cloned.

    I understand that when it posts back, the code behind will not see it.  However, I am going to put a javascript function on the Save button to take the values in the new rows and store them in a hidden text box on the page.  The save routine can take the values out and figure out what the user entered.

    Thanks!

    Thursday, December 9, 2010 12:59 AM