You must Sign In to post a response.
  • Category: .NET

    How to retrieve arecord from database and show as pdf in iframe when dropdown box is selec

    actually i have written code but that record is downloading in to my system
    so below is my code any body help me where is the error

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using iTextSharp.text.html;
    using iTextSharp.text.html.simpleparser;
    using System.Text;
    //using System.Data.SqlClient;
    using System.Net;

    public partial class dropdown_to_gridview : System.Web.UI.Page
    {

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void GridViewBind()
    {
    string cs = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
    SqlConnection con = new SqlConnection(cs);
    SqlCommand cmd = new SqlCommand("select * from employeep where Salary ='" + DropDownList1.SelectedValue + "'", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    }
    protected void btnExportPDF_Click(object sender, EventArgs e)
    {
    string cs = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
    SqlConnection con = new SqlConnection(cs);
    SqlCommand cmd = new SqlCommand("select * from employeep where Salary ='" + DropDownList1.SelectedValue + "'", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();

    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition",
    "attachment;filename=report.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
    pdfFrame.Attributes.Add("sr", "pdfDoc");
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    /* Verifies that the control is rendered */
    }

    }
  • #761526

    Hello Velidiviram,

    Add the below code :

    pdfFrame.Attributes["src"] = @"E:\Study\Visual_Studio_2015_Succinctly.pdf";

    Hope this will help you.


    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761530

    hi

    try this code after generate pdf file


    <iframe id="ifrm1" runat="server" src="pdf file"></iframe>


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments