RadGrid Export - Dynamic columns, data does not show

4 posts, 0 answers
  1. James
    James avatar
    53 posts
    Member since:
    Jun 2009

    Posted 10 Oct 2012 Link to this post

    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:

    {
        //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();
    }
  2. James
    James avatar
    53 posts
    Member since:
    Jun 2009

    Posted 11 Oct 2012 Link to this post

    I was able to figure this out using the docs, imagine that!

    http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Keith
    Keith avatar
    12 posts
    Member since:
    Sep 2011

    Posted 26 Jul 2013 Link to this post

    What did you change based on the doc?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jul 2013 Link to this post

    Hi Keith,

    This issue can appear when the DataField value of the column does not matches the underlying source column name.Please revise your code.If you cant still solve the issue,please provide your code.

    Thanks,
    Princy
Back to Top