Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want a code for Converting data into PDF from Gridview

when i select employee name from dropdown the information related to employee is display in Gridview and also in pdf formate
Posted

 
Share this answer
 
Code for select data from database

C#
CR_visitor_Pass cr = new CR_visitor_Pass();
search_Record SR_obj = new search_Record();
DataTable DT = new DataTable();
DT = SR_obj.Search_Record_For_PrintPass(pass_obj);
cr.SetDataSource(DT);
MemoryStream oStream;
oStream = (MemoryStream)
                            cr.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Cache["testr"] = oStream.ToArray();

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('Pdfconvert.aspx');", true);



In Pdfconvert.Aspx following code


C#
protected void Page_Load(object sender, EventArgs e)
        {

            ArrayList ary = new ArrayList();
            ary.Add(Cache["testr"]);
            Cache.Remove("testr");

            BinaryFormatter f = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            f.Serialize(ms, ary);

            CR_visitor_Pass cr = new CR_visitor_Pass();
            cr.Load(Server.MapPath("~/CR_visitor_Pass.rpt"));            
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(ms.ToArray());
            Response.End();
        }
 
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