Monday, June 14, 2010

Export ASP.Net GridView to PDF and XLS using iTextSharp

http://www.aspsnippets.com/Articles/Export-ASP.Net-GridView-to-PDF-with-Custom-Columns-Widths-using-iTextSharp.aspx

http://sourceforge.net/projects/itextsharp/

Adding Custom Header in Gridview

protected void gViewEdit_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView gView = (GridView)sender;
GridViewRow gViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell tblCell = new TableCell();
tblCell.Text = "Admission Report";
tblCell.ColumnSpan = 13;
tblCell.HorizontalAlign = HorizontalAlign.Center;
tblCell.Font.Size = 16;
tblCell.Font.Bold = true;
gViewRow.Cells.Add(tblCell);
gView.Controls[0].Controls.AddAt(0, gViewRow);
}
}