Reputation: 1489
I'm exporting temporary DataGrid to PDF by using the Following Code,
System.Data.DataTable dt = new System.Data.DataTable();
CDbAccess db = new CDbAccess();
IDbConnection conn = db.GetConnectionInterface();
conn.Open();
IDbCommand cmd = db.GetCommandInterface(str);
IDbDataAdapter da = db.GetDataAdapterInterface(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
try
{
da.SelectCommand = cmd;
da.Fill(ds);
dt = ds.Tables[0];
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
// da.Dispose();
conn.Dispose();
}
GridView GridView1 = new GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.HeaderStyle.BackColor = System.Drawing.Color.DeepSkyBlue;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=BugReport.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();
And the Output is looking worse, so that i need to align the Output.
And i just want to set Font color and Font Size to particular column.
How to set it using C#?
Upvotes: 0
Views: 7488
Reputation: 5474
Columns property references the columns in your grid-view setup, if you wanted to just access a targeted column in a specific row then:
GridView1.Rows[0].Cells[0].ControlStyle.Font.Size = 40;
Upvotes: 1