Export GridView to Excel using jQuery in ASP.Net

Last Reply on May 09, 2017 07:15 AM By AnandM

Posted on May 09, 2017 02:06 AM

Hi,

I was able to get the data from the JSON to datatable using the link here

http://www.aspforums.net/Threads/136177/Read-Complex-Json-and-convert-Json-string-to-DataTable-using-jQuery-Ajax-in-ASPNet/

But the rows do not show up in the page source since we are binding to gridview using jquery.

Here is what page source looks like

<table cellspacing="0" rules="all" border="1" id="gvJsonData1" style="border-collapse:collapse;">
		<tr>
			<th scope="col">id</th><th scope="col">Billingname</th><th scope="col">Companyname</th><th scope="col">Address</th><th scope="col">Email</th><th scope="col">Mobile</th><th scope="col">value</th><th scope="col">currency</th><th scope="col">status</th>
		</tr><tr>
			<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
		</tr>
	</table>

Can u suggest a solution? I need to get the data table to excel and upload it to sqlserver.

Posted on May 09, 2017 04:59 AM

Hi Vikash21,

You cant access the gridview values in code behind as it is binded dynamically using jquery so you can access them at client side only and do the necessary operation on gridview at client side only.

So you need to import the gridview through client side using jQuery or javascript so refer below link for exporting the gridview to Excel using jquery.

Export HTML table or Gridview to Excel using JavaScript or jQuery in ASP.Net


Posted on May 09, 2017 07:15 AM
Vikash21 says:
var rows = $('[id*=GridView1] tr:not(:has(th))');

 replace above code with below

var rows = $('[id*=gvJsonData1] tr:not(:has(th))');