asp.net - Print multiple gridviews in c# using single procedure -
This is my work code I need some help in making this trend because I < code> itextsharp When I click on the However, it does not print This is what I need: How do I do this? Yok can create a public function for export PDFs. I will write how I use it. For example create a public class general.cs. And add this code to it. When you only need a PDF, call this function print button, it runs
MySelectProcedure1 and the result of the table Is downloaded to PDF in the
DataTable .
Secure Zero btnPrint_Click (Object Sender, EventArgs e) {Process ("MySelectProcedure1"); Process ("MySelectProcedure2"); } Secure zero process (string process) {connection con = new connection (); SqlDataAdapter da; Datatile dt; Con.con = New SqlConnection (con.str); Con.cmd.CommandText = Proc; Con.cmd.CommandType = CommandType.StoredProcedure; da = new SqlDataAdapter (); Da.SelectCommand = con.cmd; Dt = new datatable (); Try {con.con.Open (); Da.Fill (DT); Print (dt); } Hold (Exception Pre) {} Finally {con.con.close (); Con.con.Dispose (); }} Protected Zero Print (DataTable DT) {GridView GridView1 = New GridView (); GridView1.AllowPaging = false; GridView1.DataSource = dt; GridView1.DataBind (); Response.ContentType = "Apps / PDF"; Response.AddHeader ("content-type", "attachment; file name = datalet.pdf"); Response.Cache.SetCacheability (HttpCacheability.NoCache); StringWrite SW = new stringwriter (); HtmlTextWriter hw = new HtmlTextWriter (sw); GridView1.RenderControl (hw); Stringreader sr = new string reader (sw.ToString ()); Document pdfDoc = new document (pages 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 (); }}
MySelectProcedure1 in the same PDF.
MySelectProcedure1
Public Static Zero Exports PDF (Datatelle DT1, Datatile DT2) {HTTPNXT. Current. response. Clear (); HttpContext.Current.Response.ContentType = "Apps / PDF"; HttpContext.Current.Response.AddHeader ("Content-Properties", string.format ("attachment; filename = {0} .pdf", "PDFExport"); HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.NoCache); // First for datatale system IO.StringWriter stringWrite1 = new system.IO.StringWriter (); System.Web.UI.HtmlTextWriter htmlWrite1 = new HtmlTextWriter (stringWrite1); DataGrid MyDataGrid1 = New DataGrid (); MyDataGrid1.DataSource = dt1; MyDataGrid1.DataBind (); MyDataGrid1.RenderControl (htmlWrite1); // For the second datatelle system. Io String Vitter String Vector 2 = New System Io Stringwriter (); System.Web.UI.HtmlTextWriter htmlWrite2 = new HtmlTextWriter (stringWrite2); DataGrid Myadatgrid 2 = New DataGrid (); MyDataGrid2.DataSource = dt2; MyDataGrid2.DataBind (); MyDataGrid2.RenderControl (htmlWrite2); // You can add more datable string reader sr = new stringreader (stringwirt 1.ToString () + stringwrite2.ToString ()); Document pdfDoc = new document (new rectangle (288 f, 144 f), 10 f, 10 f, 10 f, 0 f); pdfDoc.SetPageSize (PageSize.A4.Rotate ()); HTMLWorker htmlparser = new HTMLWorker (pdfDoc); PdfWriter.GetInstance (pdfDoc, HttpContext.Current.Response.OutputStream); PdfDoc.Open (); Htmlparser.Parse (SR); PdfDoc.Close (); HttpContext.Current.Response.Write (pdfDoc); HttpContext.Current.Response.End (); }
secure void lnkExportPDF_Click (object sender, EventArgs e) {General .ExportPDF (rptList); } Public Override Zero VerifyRenderingInServerForm {Control} {}
Comments
Post a Comment