I am using the data from the RadGrid here to export.
Design of the Grid
Code at the .cs file
Formatting The PDF
- #region--Declaring Head Part
- for The Pdf Export--
- stringheaderMiddleCell = "<h2>My Contact Details </h2>";
- stringheaderLeftCell = "<imgsrc=\"Images/sushibar.jpg\" alt=\"sushi bar\" style=\"width:64px; height: 64px;\" />";
- stringfooterMiddleCell = "<?page-number?>";#
- endregion
- privatevoidExportToPdf()
- {#region--Export Selected Data To Pdf--
- try
- {
- RadGridTotalCOD.AllowPaging = true;
- RadGridTotalCOD.AllowFilteringByColumn = false;
-
- LoadTotalCod();#
- region--Export with format removed--
- RadGridTotalCOD.ExportSettings.ExportOnlyData = true;
- RadGridTotalCOD.ExportSettings.Pdf.BorderStyle = GridPdfSettings.GridPdfBorderStyle.Thin;
- RadGridTotalCOD.ExportSettings.Pdf.BorderType = GridPdfSettings.GridPdfBorderType.NoBorder;
- RadGridTotalCOD.ExportSettings.Pdf.BorderType = GridPdfSettings.GridPdfBorderType.AllBorders;
- RadGridTotalCOD.ExportSettings.Pdf.PageHeader.MiddleCell.Text = headerMiddleCell;
- RadGridTotalCOD.ExportSettings.Pdf.PageHeader.MiddleCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Center;
-
- RadGridTotalCOD.ExportSettings.Pdf.PageHeader.LeftCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Center;
- RadGridTotalCOD.ExportSettings.Pdf.PageFooter.MiddleCell.Text = footerMiddleCell;
- RadGridTotalCOD.ExportSettings.Pdf.PageFooter.MiddleCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Center;#
- endregion
- string Date = DateTime.Now.ToString("dd/MMM/yyyy");
- RadGridTotalCOD.ExportSettings.FileName = "Client Address " + " " + Date;#
- region--Making Visible false some of the column before exporting--
-
- (RadGridTotalCOD.MasterTableView.GetColumn("TemplateColumn") asGridTemplateColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("TemplateColumn") asGridTemplateColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("TemplateColumn2") asGridTemplateColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("TemplateColumn2") asGridTemplateColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("OrderId") asGridBoundColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("OrderId") asGridBoundColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("OrderNo") asGridBoundColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("OrderNo") asGridBoundColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("OrderDate") asGridBoundColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("OrderDate") asGridBoundColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("Email") asGridBoundColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("Email") asGridBoundColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("Prices") asGridBoundColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("Prices") asGridBoundColumn).Display = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("Status") asGridBoundColumn).Visible = false;
- (RadGridTotalCOD.MasterTableView.GetColumn("Status") asGridBoundColumn).Display = false;#
- endregion# region--Making visible true on a Regular Basis--(RadGridTotalCOD.MasterTableView.GetColumn("ShippingAddress") asGridBoundColumn).Visible = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("ShippingAddress") asGridBoundColumn).Display = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("Pincode") asGridBoundColumn).Visible = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("Pincode") asGridBoundColumn).Display = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("CityName") asGridBoundColumn).Visible = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("CityName") asGridBoundColumn).Display = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("StateName") asGridBoundColumn).Visible = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("StateName") asGridBoundColumn).Display = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("CountryName") asGridBoundColumn).Visible = true;
- (RadGridTotalCOD.MasterTableView.GetColumn("CountryName") asGridBoundColumn).Display = true;#
- endregion
-
- RadGridTotalCOD.MasterTableView.HierarchyDefaultExpanded = false;
- RadGridTotalCOD.MasterTableView.ExportToPdf();
-
- RadGridTotalCOD.AllowFilteringByColumn = true;
- }
- catch (ArgumentNullExceptionExc)
- {
- LblErrorMsg.Text = "Application Error : " + Exc.Message;
- }
- catch (InvalidCastExceptionExc)
- {
- LblErrorMsg.Text = "Application Error : " + Exc.Message;
- }
- catch (InvalidOperationExceptionExc)
- {
- LblErrorMsg.Text = "Application Error : " + Exc.Message;
- }
- catch (FormatExceptionExc)
- {
- LblErrorMsg.Text = "Application Error : " + Exc.Message;
- }
- catch (ExceptionExc)
- {
- LblErrorMsg.Text = "Application Error : " + Exc.Message;
- }#
- endregion
- }