Explore and Learn tutorials and articles on ASP.NET, MVC, .NET Core, SQL Server, C#, VB.NET, AJAX, jQuery, Angular, Entity Framework, Web API, HTML, charts, and more latest technologies.
This article gives an explanation about how to export GridView to excel using jquery with bootstrap 4 in asp.net web forms as well as also show how to bind a GridView using a Datatable.
In my previous article, I explained how to export an angular js table in an excel using jquery plugin with bootstrap 4 in asp.net web forms. I got many emails and comments where many of beginners requested to write and publish an article for export HTML table or GridView to excel without using angular js, few of them also requested for sample/demo source code for export GridView to excel, Finally, In this article, I'll explain how to bind GridView as well as how to export GridView to excel using table2excel JQuery in ASP.NET web forms.
Requirement
1) Explain how to export GridView to excel using JQuery plugin in ASP.NET web forms with example.
Implementation
If you read my previous article then you know, I explained what is table2excel jQuery plugin as well as its parameters and use of this jQuery plugin for export HTML table to excel. To read my previous article about export HTML table to excel using table2excel JQuery plugin you can visit this reference link.
Now, let's take one simple example of the employee management system, where we will bind the list of the employees with basic details of employees such as employee Id, employee name, department, designation, company name into GridView using Datatable, then we will export GridView to export using table2excel JQuery plugin.
Example
First, you have to include jquery.min.js, as well as table2excel.js file in your project and then put the following lines in the aspx file or master page of asp.net web forms application before end <head> tag to link that javascript with your application.
Finally, we will design our aspx form with bootstrap 4, so include CDN links of bootstrap before the end <head> tag and then design for with GridView and one simple HTML button for export GridView to excel.
As you can see in the javascript written above here, we have called a javascript function on click of btnExporttoExcel, we will use this button for export data in the excel sheet. Then we have called function table2excel for GridView grdEmp and we've passed parameters filename for the name of excel sheet, exclude image, links and inputs parameters for excluding image, links and inputs while export excels sheets.
Note: You can export any HTML table using table2excel JQuery plugin either it can be simple HTML Table, AngularJs table, Jquery Datatable, Web grid, GridView or anything else, you just have to replace id parameter of an export button and HTML table in the script above.
Now, we will prepare a function GetEmployeeData() that returns Datatable with columns employee Id, employee name, department, designation and company name.
Now, you have to run your application while the user clicks on the "Export to Excel button" created JavaScript function will call and export all the records of GridView to excel as shown in the output window below.
Output
Summary
This article gives an explanation about the export GridView to excel using Jquery in asp.net web forms
Codingvila provides articles and blogs on web and software development for beginners as well as free Academic projects for final year students in Asp.Net, MVC, C#, Vb.Net, SQL Server, Angular Js, Android, PHP, Java, Python, Desktop Software Application and etc.
Thank you for your valuable time, to read this article, If you like this article, please share this article and post your valuable comments.
Once, you post your comment, we will review your posted comment and publish it. It may take a time around 24 business working hours.
Sometimes I not able to give detailed level explanation for your questions or comments, if you want detailed explanation, your can mansion your contact email id along with your question or you can do select given checkbox "Notify me" the time of write comment. So we can drop mail to you.
If you have any questions regarding this article/blog you can contact us on info.codingvila@gmail.com