Generate pdf document from gridview data and store on web server – Part 59
The HTML and the code used in the demo, can be found at the link below.
Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists
Please watch Part 58, before proceeding with this video.
Step 1: Create an asp.net web application project. Add a folder with name “PDFDocuments” to the project. We will be using this folder to store the dynamically generated pdf document.
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/itextsharp/. 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.
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)
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();
GridView1.DataSource = ds;