| 1 public class MyClass : LayoutsPageBase |
| 2 { |
| 3 protected RadGrid grdView; |
| 4 protected RadComboBox cboViews; |
| 5 protected Button btnExport; |
| 6 private string curview; |
| 7 |
| 8 protected override void OnLoad(EventArgs e) |
| 9 { |
| 10 if (!Page.IsPostBack) |
| 11 { |
| 12 grdView.Visible = false; |
| 13 } |
| 14 else |
| 15 { |
| 16 grdView.Visible = true; |
| 17 } |
| 18 } |
| 19 |
| 20 protected void lbtnGo_Command(object sender, CommandEventArgs e) |
| 21 { |
| 22 grdView.Rebind(); |
| 23 } |
| 24 |
| 25 protected void grdView_NeedDataSource(object o, GridNeedDataSourceEventArgs e) |
| 26 { |
| 27 if (cboViews.SelectedValue != "") |
| 28 { |
| 29 curview = cboViews.SelectedValue; |
| 30 |
| 31 Database db = DatabaseFactory.CreateDatabase(); |
| 32 DbCommand getleview = db.GetStoredProcCommand("MyStoredProcedure"); |
| 33 |
| 34 db.AddInParameter(getleview, "View", DbType.String, curview); |
| 35 |
| 36 DataSet ds = db.ExecuteDataSet(getleview); |
| 37 DataTable dt = ds.Tables[0]; |
| 38 |
| 39 grdView.DataSource = dt; |
| 40 } |
| 41 else |
| 42 { |
| 43 grdView.DataSource = string.Empty; |
| 44 } |
| 45 } |
| 46 |
| 47 protected void btnExport_Click(object sender, EventArgs e) |
| 48 { |
| 49 ConfigureExport(); |
| 50 grdView.MasterTableView.ExportToExcel(); |
| 51 } |
| 52 |
| 53 public void ConfigureExport() |
| 54 { |
| 55 grdView.ExportSettings.ExportOnlyData = true; |
| 56 grdView.ExportSettings.IgnorePaging = true; |
| 57 grdView.ExportSettings.OpenInNewWindow = true; |
| 58 if (cboViews.SelectedValue != "") |
| 59 { |
| 60 curview = cboViews.SelectedValue; |
| 61 grdView.ExportSettings.FileName = "SomeFileName_" + curview; |
| 62 } |
| 63 else |
| 64 { |
| 65 grdView.ExportSettings.FileName = "SomeFileName"; |
| 66 } |
| 67 } |
| 68 |
| 69 protected void RadGrid1_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e) |
| 70 { |
| 71 if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow) |
| 72 { |
| 73 if (e.Row.Cells[0] != null && ((string)e.Row.Cells[0].Data.DataItem).Contains("U")) |
| 74 { |
| 75 e.Row.Cells[0].StyleValue = "MyCustomStyle"; |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 protected void RadGrid1_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e) |
| 81 { |
| 82 foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles) |
| 83 { |
| 84 if (style.Id == "headerStyle") |
| 85 { |
| 86 style.FontStyle.Bold = true; |
| 87 style.FontStyle.Color = System.Drawing.Color.Gainsboro; |
| 88 style.InteriorStyle.Color = System.Drawing.Color.Wheat; |
| 89 style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; |
| 90 } |
| 91 else if (style.Id == "itemStyle") |
| 92 { |
| 93 style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke; |
| 94 style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; |
| 95 } |
| 96 else if (style.Id == "alternatingItemStyle") |
| 97 { |
| 98 style.InteriorStyle.Color = System.Drawing.Color.LightGray; |
| 99 style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; |
| 100 } |
| 101 } |
| 102 |
| 103 Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle"); |
| 104 myStyle.FontStyle.Bold = true; |
| 105 myStyle.FontStyle.Italic = true; |
| 106 myStyle.InteriorStyle.Color = System.Drawing.Color.Gray; |
| 107 myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid; |
| 108 e.Styles.Add(myStyle); |
| 109 } |
| 110 } |
| |