Question

I am trying to generate a telerik report table dynamically. Actually, after lots of efforts besides surfing the web I have come to the following code which works fine but not presenting the desired output. Here is the code:

private void table1_ItemDataBinding(object sender, EventArgs e)
    {
        // Get data and bind it to the table
        var processingTable = (sender as Telerik.Reporting.Processing.Table);
        var data = GenerateTable(DomainClass.GetCurrentAsset());
        if (processingTable != null) processingTable.DataSource = data;

        // Better clear table before binding
        table1.ColumnGroups.Clear();
        table1.Body.Columns.Clear();
        table1.Body.Rows.Clear();

        HtmlTextBox txtGroup;
        HtmlTextBox txtTable;
        //int rowIndex = 0;

        for (int i = 0; i <= data.Columns.Count - 1; i++)
        {
            var tableGroupColumn = new TableGroup();
            table1.ColumnGroups.Add(item: tableGroupColumn);

            txtGroup = new HtmlTextBox
                           {
                               Size = new SizeU(Unit.Inch(2.1), Unit.Inch(0.3)),
                               Value = data.Columns[i].ColumnName,
                               Style =
                                   {
                                       BorderStyle = { Default = BorderType.Solid },
                                       BorderColor = { Default = Color.Black }
                                   },
                           };
            tableGroupColumn.ReportItem = txtGroup;

            txtTable = new HtmlTextBox()
                           {
                               Size = new SizeU(Unit.Inch(2.2), Unit.Inch(0.3)),
                               Value = "=Fields." + data.Columns[i].ColumnName,
                               //Value = data.Rows[rowIndex][i].ToString(),
                               Style =
                                   {
                                       BorderStyle = { Default = BorderType.Solid },
                                       BorderColor = { Default = Color.Black }
                                   }
                           };

            table1.Body.SetCellContent(0, columnIndex: i, item: txtTable);
            //rowIndex++;
            table1.Items.AddRange(items: new ReportItemBase[] { txtTable, txtGroup });
        }
    }

Here is a picture of DataTable which contains the table data:

Data Table Image of the Report

Finally, the current out put which is of course not what needed:

Report Result (Not Desired)

So the problem is; The Account_Price column does not display the Prices, though retrieved from the data store and can be seen in the data table picture above.

I have traced line by line of the code and could find out the prices as tracing the code. But I have no idea why they are not shown in the browser.

Hope any one could help me, Thank you very much

Was it helpful?

Solution

Apparently, this is a newer issue with the later Telerik reporting.

I found the answer in the Telerik forums here: http://www.telerik.com/community/forums/reporting/telerik-reporting/incorrect-dynamic-table-columns.aspx

Basically, you need to assign a unique name the TableGroup column:

TableGroup tableGroupColumn = new TableGroup();
//add this :
tableGroupColumn.Name = i.ToString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top