Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I m new for Ajax,

I want to add a row(blank row) to gridview using javascript/Ajax(page method or else) on button click so that page can not be postback.
And add all rows of gridview to database using page method on button click.

can u plz help me?

Thanks in advance.
swapnil
Posted

1 solution

You don't need to use any server-side code to add a row. The gridview is rendered as a html table by default, so your JavaScript just needs to add another tr, usually at the bottom, such as this

JavaScript
function AddRow()
{
  $("#tableID").append("<table><tbody><tr><td>Fill in as necessary<table><tbody><tr><td></td></tr></tbody></table></td></tr></tbody></table>");
}


Reading the data could be like this

JavaScript
function ReadValues()
{
  $("#tableID td").each(function()
   {
     // find ocntrol and value in each td
   });
}


Using an AJAX method to add or read data from a GridView won't work since the AJAX call is out of band and the GridView is a server control which needs the ASP.NET page lifecyle to reconstitue it from page data or view state.
 
Share this answer
 

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