http://csharp-video-tutorials.blogspo...
Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat...
In this video, we will discuss about exporting gridview data to PDF.
Step 1: Create an asp.net web application project.
Step 2: Drag and drop a gridview control and a button control on webform1.aspx. Autoformat the gridview control to use "BrownSugar" scheme. Double click on the button control, to generate click event handler method.
Step 3: To generate PDF documents we will be using open source assembly - iTextSharp.dll. This assembly can be downloaded from http://sourceforge.net/projects/itext.... After you download the assembly, add a reference to it, from your web application.
a) In Solution Explorer, right click on the "References" folder and select "Add Reference"
b) Browse to the folder where you have downloaded the assembly and Click OK.
Step 4: Add the following "USING" statements, in your code-behind file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
Step 5: Copy and paste the following code. The code is well commented and is self-explanatory.
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack) { BindGridViewData(); }
}
// ADO.NET code to retrieve data from database
private void BindGridViewData()
{ string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlDataAdapter da = new SqlDataAdapter("Select * from tblEmployee", con); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); }
}
protected void Button1_Click(object sender, EventArgs e)
{ int columnsCount = GridView1.HeaderRow.Cells.Count; // Create the PDF Table specifying the number of columns PdfPTable pdfTable = new PdfPTable(columnsCount); // Loop thru each cell in GrdiView header row foreach(TableCell gridViewHeaderCell in GridView1.HeaderRow.Cells) { // Create the Font Object for PDF document Font font = new Font(); // Set the font color to GridView header row font color font.Color = new BaseColor(GridView1.HeaderStyle.ForeColor); // Create the PDF cell, specifying the text and font PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewHeaderCell.Text, font)); // Set the PDF cell backgroundcolor to GridView header row BackgroundColor color pdfCell.BackgroundColor = new BaseColor(GridView1.HeaderStyle.BackColor); // Add the cell to PDF table pdfTable.AddCell(pdfCell); } // Loop thru each datarow in GrdiView foreach (GridViewRow gridViewRow in GridView1.Rows) { if (gridViewRow.RowType == DataControlRowType.DataRow) { // Loop thru each cell in GrdiView data row foreach (TableCell gridViewCell in gridViewRow.Cells) { Font font = new Font(); font.Color = new BaseColor(GridView1.RowStyle.ForeColor); PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewCell.Text, font)); pdfCell.BackgroundColor = new BaseColor(GridView1.RowStyle.BackColor); pdfTable.AddCell(pdfCell); } } } // Create the PDF document specifying page size and margins Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f); // Roate page using Rotate() function, if you want in Landscape // pdfDocument.SetPageSize(PageSize.A4.Rotate()); // Using PageSize.A4_LANDSCAPE may not work as expected // Document pdfDocument = new Document(PageSize.A4_LANDSCAPE, 10f, 10f, 10f, 10f); PdfWriter.GetInstance(pdfDocument, Response.OutputStream); pdfDocument.Open(); pdfDocument.Add(pdfTable); pdfDocument.Close(); Response.ContentType = "application/pdf"; Response.AppendHeader("content-disposition", "attachment;filename=Employees.pdf"); Response.Write(pdfDocument); Response.Flush(); Response.End();
}
At this point, run the application and click on the button. The data gets exported to PDF as expected. If you are using Google chrome as your browser, you may get a browser warning stating - this type of file can harm your computer do you want to keep Employees.pdf anyway? This is a know issue with google chrome. Internet explorer, works fine.
asp.net core docker Export gridview to pdf in asp.net - Part 58 | |
218 Likes | 218 Dislikes |
53,652 views views | 524K followers |
Education | Upload TimePublished on 18 Apr 2013 |
Related keywords
wcf vs web api,sql server management studio,c#.net versions,webkinz,webadvisor,craigslist nj,asp.net core 3,ajax players,csharp corner,asp.net machine account,asp.net core dependency injection,c#.net developer,document.addeventlistener,ajax ontario,grid view xamarin forms,c#.net online compiler,asp.net mvc tutorial,content lab la nacion,tutorialspoint python,c#.net interview questions,services briefcase,data entry,ajax jquery,craigslist ny,server memes,document ready,services online,server resume,tutorialspoint javascript,gridview rowcommand,mvcc connect,services technologies gps,grid view html,document js,server jobs,website,mvc tutorial,costco hours,wcf service application,tutorialspoint spring,serverless,document ready js,wcf cat,services & training hse colombia sas,citibank,ajax parking,sql database,mvconnect,asp.net guida,cunyfirst,csharp online,c#.net notes pdf,http://asp.net,server 2019,ado.net descargar,chernobyl,ado.net visual studio 2019,data star trek,ado.net visual studio 2017,contentamiento,sql like,wcfm,tutorial gateway,grid view c# asp.net,asp.net core mvc,ajax soccer,data scientist salary,wcfi,data mining,craigslist,tutorialspoint python 3,sql developer,webster,services transmission company sas,sql group by,gridviewrow,mvc near me,c#.net framework,mvc map,asp.net download,sql between,ado.net c# pdf,wcf 2019 nba,ado.net ventajas y desventajas,wcf tutorial,tutorials dojo,central park 5,ado.net c#,gridview android example,server status,server jobs nyc,asp.net core swagger,gridview css,gridview yii2,server error in '/' application,data entry jobs,services windows,asp.net core 3.0,sql injection,gridview asp.net,tutorialspoint c#,c#.net vs asp.net,ado.net entity data model,sql insert,tutorialspoint tableau,contenta,sqlyog,sql server,tutorials by a,servicenow,c#.net to vb.net,c#.net w3schools,contento,csharp array,c#.net projects,csharp enum,asp.net core 2. guida completa per lo sviluppatore,gridview c# asp.net,grid view devexpress mvc,server status ffxiv,c#.net basics,document.createelement,cheap flights,asp.net core hosting,tutorialspoint java,webmd,documentary,ado.net dataset,tutorial meaning,cnn,website builder,asp.net web api,weber grills,sql server 2017,data breach,asp.net core download,webster bank,gridview column width,document.getelementbyid,grid view en android studio,tutorial teacher,ajax post,services fms publish announcement,gridview devexpress,services.msc no abre,content manager assetto corsa,content creator,csharp operator,content manager,server duties,contentura,tutorial on variational autoencoders,csharp random,c#.net latest version,mvcsd,mvcsc,ado.net pdf,asp.net core configuration,contentful,mvc medical,wcfs international curriculum,grid view selectedindexchanged in asp.net,wcf api,server jobs near me,webex,sql meaning,sql tutorial,sql commands,data universe,ado.net entity framework,content lab,c#.net pdf,document.queryselectorall,contentar,contento significado,content id,ajax greek,csharp tutorial,ado.net connection,asp.net identity,grid view devexpress,gridview android,databricks,gridview bootstrap,content words,grid view react native,data analyst,wcf web service,mvc webadvisor,web store,mvctc,content //com.android.browser.home/,ado.net core,document.ua,gridview datasource,wcf one piece,document flow,c#.net core,weber grill parts,webtoon,tutorials by hugo,mvc design pattern,servers for minecraft,ado.net tutorial,grid view android,document onload,services angular,tutorial definition,tutorial on excel,asp.net cos'è,csharp assembly,sql join,asp.net core web api,wccftech,gridview flutter,data warehouse,asp.net zero,csharp foreach,sql date format,chase,c#.net tutorial pdf,serverless architecture,data science,wcf c#,grid view xamarin,server books,ado.net mysql,data scientist,ajax deadpool,cvs,wcf soap,wcf test client,cool math games,servicestack,asp.net core identity,sql union,asp.net core logging,gridview devexpress c#,grid view bootstrap,documents,wcf nba,csharp download,wcfi foundation,wcf authentication,tutorials near me,web of dreams,documents google,serverminer,gridview pagination,ajax cleaner,tutorial for windows 10,webassign,ado.net vs entity framework,data lake,csharp list,gridview height,grid view flutter,asp.net mvc,asp.net core tutorial,sqlite,gridview c#,ajax roster,mvc architecture,http://ado.net,server hosting,document.cookie,ajax dish soap,grid view android example,capital one,grid view c#,server rack,tutorialspoint html,csharp interface,contento sinonimos,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,content marketing,asp.net core signalr,services manager,mvc framework,ajax paving,data analysis,tutorialspoint spring boot,c#.net concatenate strings,csharp online compiler,data analyst salary,services tag dell,csharp switch,c#.net mvc,csharpstar,tutorialspoint,ajax meaning,contentina,csharp-video-tutorials.blogspot,document.write,tutorial mission gta online,csharp string format,asp.net core github,document online,ajax fc,sql formatter,credit karma,services group,wcf ria services,calculator,data analytics,document.getelementsbytagname,services google play apk,asp.net core 3 release date,c#.net tutorial,server job description,webcam,mvc hours,webmd symptom,ajax call,asp.net core,server pro,webcrims,services sas,document.getelementsbyclassname,tutorialspoint java compiler,datadog,document object model,csharp to json,grid view asp.net bootstrap,college football,csharp dictionary,tutorial.mc-complex,tutorialspoint sql,server side rendering,mvc nj,tutorialspoint spark,ado.net oracle,csharp to vb.net,document.queryselector,webstaurant,tutorial systems,datacamp,tutorialsystems,grid view yii2,ajax jersey,asp.net core razor pages,asp.net core environment variables,century 21,services consultores,services consulting,gridview hide column,services.msc,ajax marvel,tutorial synonym,sql update,asp.net tutorial,ado.net entity data model visual studio 2019,mvc2,grid view css,ado.net entity data model visual studio 2017,c#.net tutorialspoint,chase online,costco,gridview bootstrap 4,ajax tavern,tutorialsteacher,ajax javascript,grid view laravel,c#.net programs,database,services desk,data visualization,grid view scroll bar in asp.net,content traduccion,grid view asp.net,mvc pattern,ado.net sql server,mvcu,contento es un adjetivo,asp.net core middleware,gridview xamarin forms,tutorial music,mvcc,webmail,mvci,
Không có nhận xét nào:
Đăng nhận xét