Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have a GridView, which is getting bind with data from data table and i will filter data from table and then bind to Gridview,
How to Export data to Excel which is binded to gridview.

Please Help Me ASAP

C#
BindRequestDetails();
           //dtRequestDetails = dsRequests.Tables["CertificationRequest"];
           DataTable dtReport = dtRequestDetails;
           string[] strColumns = { "RequestID", "RequestStatus", "EmployeeName", "ProjectName", "CertificationName", "PercentageObtained", "PassingPercentage", "ExpectedExamFee", "ActualExamFee", "ReimbursementAmount", "ValidTillDate", "PrimarySkills" };
           DataTable reportTable = dtReport.DefaultView.ToTable(dtReport.TableName, false, strColumns);
           string strFileNameForExport = "Report.xls";
           reportTable.Columns["RequestID"].ColumnName = "Request ID";
           reportTable.Columns["RequestStatus"].ColumnName = "Request Status";
           reportTable.Columns["EmployeeName"].ColumnName = "Employee Name";
           reportTable.Columns["ProjectName"].ColumnName = "Project Name";
           reportTable.Columns["CertificationName"].ColumnName = "Certification Name";
           reportTable.Columns["PercentageObtained"].ColumnName = "Percentage Obtained";
           reportTable.Columns["PassingPercentage"].ColumnName = "Passing Percentage";
           reportTable.Columns["ExpectedExamFee"].ColumnName = "Expected Exam Fee";
           reportTable.Columns["ActualExamFee"].ColumnName = "Actual Exam Fee";
           reportTable.Columns["ReimbursementAmount"].ColumnName = "Reimbursement Amount";
           reportTable.Columns["ValidTillDate"].ColumnName = "ValidTill Date";
           reportTable.Columns["PrimarySkills"].ColumnName = "Primary Skills";

           try
           {
               OCSCommon.GenerateExcelAndDownload(strFileNameForExport, reportTable);
           }
Posted
Updated 29-Jul-13 7:50am
v4
Comments
ZurdoDev 29-Jul-13 13:32pm    
There are lots of samples online. Have you tried one?
vana Bharadwaj 29-Jul-13 13:33pm    
ya i did, actually after Click on Export to excel button, the page will remain loading, and other button page is not working.
ZurdoDev 29-Jul-13 13:39pm    
Then post your relevant code using the improve question link and let us know where you are stuck.

Check here for Export to excel from datatable
http://kishsharmasoftcode.blogspot.in/[^]
 
Share this answer
 
I've answered a couple just like this recently. Here's Microsoft's walkthrough: http://support.microsoft.com/kb/306022[^].

It sounds like you may be experiencing a common problem--you code it right, but the processing is very slow. To speed that up, output to Excel via an array into a range instead of cell by cell. The Microsoft link above includes an example of that.
 
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