I have a rad grid with the following settings:
grid.ExportSettings.FileName = "Export";
grid.ExportSettings.OpenInNewWindow = true;
grid.ExportSettings.ExportOnlyData = false;
grid.ExportSettings.IgnorePaging = true;
grid.ExportSettings.Excel.FileExtension = "xls";
grid.ExportSettings.Excel.Format = GridExcelExportFormat.Html;
The columns of this report are being dynamically generated. When exporting I only get the first column of date, the rest just contain "System.Data.DataRowView".
Here is the code that generates the columns:
grid.ExportSettings.FileName = "Export";
grid.ExportSettings.OpenInNewWindow = true;
grid.ExportSettings.ExportOnlyData = false;
grid.ExportSettings.IgnorePaging = true;
grid.ExportSettings.Excel.FileExtension = "xls";
grid.ExportSettings.Excel.Format = GridExcelExportFormat.Html;
The columns of this report are being dynamically generated. When exporting I only get the first column of date, the rest just contain "System.Data.DataRowView".
Here is the code that generates the columns:
{ //First clear out existing columns RadGridSearch.MasterTableView.Columns.Clear(); //Add in name column GridBoundColumn col = new GridBoundColumn(); col.HeaderText="PLC"; col.DataField="PlcName"; col.UniqueName="PlcName"; col.SortExpression="PlcName"; col.ShowFilterIcon= true; col.ItemStyle.Wrap = false; RadGridSearch.MasterTableView.Columns.Add(col); StringCollection arList = StringFormatter.DelimitedStringToStringList(RadTextBoxAR.Text, ','); int year = DateTime.Now.Year; //StringCollection dataColumns = new StringCollection(); foreach (string ar in arList) { col = new GridBoundColumn(); col.HeaderText = string.Format("{0} Sales for {1}", year - 2, ar); col.DataField = string.Format("YblSales{0}", ar); col.UniqueName = string.Format("YblSales{0}", ar); col.SortExpression = string.Format("YblSales{0}", ar); col.ShowFilterIcon = true; col.ItemStyle.Wrap = false; col.ItemStyle.HorizontalAlign = HorizontalAlign.Right; col.DataFormatString = "{0:c}"; col.Aggregate = GridAggregateFunction.Sum; RadGridSearch.MasterTableView.Columns.Add(col); col = new GridBoundColumn(); col.HeaderText = string.Format("{0} Sales for {1}", year - 1, ar); col.DataField = string.Format("LySales{0}", ar); col.UniqueName = string.Format("LySales{0}", ar); col.SortExpression = string.Format("LySales{0}", ar); col.ShowFilterIcon = true; col.ItemStyle.Wrap = false; col.ItemStyle.HorizontalAlign = HorizontalAlign.Right; col.DataFormatString = "{0:c}"; col.Aggregate = GridAggregateFunction.Sum; RadGridSearch.MasterTableView.Columns.Add(col); col = new GridBoundColumn(); col.HeaderText = string.Format("{0} Sales for {1}", year, ar); col.DataField = string.Format("TyYtdSales{0}", ar); col.UniqueName = string.Format("TyYtdSales{0}", ar); col.SortExpression = string.Format("TyYtdSales{0}", ar); col.ShowFilterIcon = true; col.ItemStyle.Wrap = false; col.ItemStyle.HorizontalAlign = HorizontalAlign.Right; col.DataFormatString = "{0:c}"; col.Aggregate = GridAggregateFunction.Sum; RadGridSearch.MasterTableView.Columns.Add(col); //dataColumns.Add(string.Format("YblSales{0}", ar)); //dataColumns.Add(string.Format("LySales{0}", ar)); //dataColumns.Add(string.Format("TyYtdSales{0}", ar)); } col = new GridBoundColumn(); col.HeaderText = "Total"; col.DataField = "Total"; col.UniqueName = "Total"; col.SortExpression = "Total"; col.ShowFilterIcon = true; col.ItemStyle.Wrap = false; col.ItemStyle.HorizontalAlign = HorizontalAlign.Right; col.DataFormatString = "{0:c}"; col.Aggregate = GridAggregateFunction.Sum; RadGridSearch.MasterTableView.Columns.Add(col); //GridCalculatedColumn ccol = new GridCalculatedColumn(); //ccol.HeaderText = "Total Sales"; //ccol.UniqueName = "total"; //ccol.SortExpression = "total"; //ccol.ShowFilterIcon = true; //ccol.ItemStyle.Wrap = false; //ccol.ItemStyle.HorizontalAlign = HorizontalAlign.Right; //ccol.DataFormatString = "{0:c}"; //ccol.Aggregate = GridAggregateFunction.Sum; //ccol.DataFields = dataColumns.ToArray(); //ccol.DataType = Type.GetType("System.Double"); //string expression = string.Empty; //for (int i = 0; i < dataColumns.Count; i++) //{ // expression += String.Format("({{{0}}} == null ? 0 : {{{0}}})+", IntFormatter.ToString(i)); //} //expression = StringFormatter.Left(expression, expression.Length - 1); //ccol.Expression = expression; //RadGridSearch.MasterTableView.Columns.Add(ccol); //rebind RadGridSearch.Rebind();}