0
protected void ExportToPdf(DataTable dt, string str)
{
ArrayList ADA = new ArrayList();
ADA.Add(FirstAssignment.SelectedItem);
ADA.Add(SecondAssignment.SelectedItem);
GridView GridView1 = new GridView();
GridView GridView2 = new GridView();
GridView1.ShowHeaderWhenEmpty = true;
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();
int i1 = GridView1.Columns.Count;
GridView1.HeaderRow.Cells[1].Text = ADA[0].ToString();
GridView1.HeaderRow.Cells[2].Text = ADA[1].ToString();
GridView1.HeaderRow.Cells[3].Text = "% of Improvement from " + (ADA[0].ToString()) + " to " + (ADA[1].ToString());
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + str + ".pdf");
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.HeaderRow.ForeColor = System.Drawing.Color.Black;
GridView1.FooterRow.ForeColor = System.Drawing.Color.Black;
GridView1.HeaderRow.Style.Add("font-Color", "Black");
GridView1.HeaderRow.Style.Add("font-size", "13px");
GridView1.HeaderRow.Style.Add("text-decoration", "none");
GridView1.HeaderRow.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
GridView1.Style.Add("font-Color", "Black");
GridView1.Style.Add("text-decoration", "none");
GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
GridView1.Style.Add("font-size", "11px");
GridView1.ForeColor = System.Drawing.Color.Black;
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
GridView1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
// HTMLWorker htmlparser1 = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(new Paragraph("hey! rashmi"));
htmlparser.Parse(sr);
pdfDoc.Close();
HttpContext.Current.Response.Write(pdfDoc);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
這是用於創建一個網格視圖。任何人都可以幫助我使用此代碼創建一個動態網格視圖。我試圖給出一個for循環GridView1.RenderControl(hw);但我得到相同的數據單網格視圖。提前感謝。使用itextsharp以pdf格式動態創建網格視圖
意味着你要GridView控件PDF? –
yes.i已創建one.i要動態創建gridview – user3239173
它是動態的目標是什麼?你有多個數據集? –