0

I have created a telerik report using Visual Studio and set the Datasource from the DataTable. I am creating the columns dynamically at runtime using Telerik.Reporting.TableGroup. Now the problem I am having here is that the report showing the same data for all of the fields and when I debug it is setting different fields for different.

The code I am using is as follows:

private void Report4_NeedDataSource(object sender, EventArgs e)
{
  DataTable dt = new DataTable();
  dt = SalesReport.reportDataTable;
  table1.DataSource = dt;

  Telerik.Reporting.HtmlTextBox textboxGroup;
  Telerik.Reporting.HtmlTextBox textBoxTable;
  table1.ColumnGroups.Clear();
  table1.Body.Columns.Clear();
  table1.Body.Rows.Clear();
  int ColCount = dt.Columns.Count;

  for (int i = 0; i <= ColCount - 1; i++)
  {
    Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
    table1.ColumnGroups.Add(tableGroupColumn);
    textboxGroup = new Telerik.Reporting.HtmlTextBox();
    textboxGroup.Style.BorderColor.Default = Color.Black;
    textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
    textboxGroup.Value = dt.Columns[i].ColumnName;
    textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));

    tableGroupColumn.ReportItem = textboxGroup;
    textBoxTable = new Telerik.Reporting.HtmlTextBox();
    textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
    textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
    table1.Body.SetCellContent(0, i, textBoxTable);
    table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });

  }

}

2 Answers 2

3

I suggest reading the following article. I found this same problem and my solution was to add unique names to the group column, label, and detail text boxes.

http://www.telerik.com/forums/incorrect-dynamic-table-columns

//Added
tableGroupColumn.Name = "group" + *something_uniquegoeshere*;

//Added
textboxGroup.Name = "label" +  *something_uniquegoeshere*;

//Added
textBoxTable.Name = "data" + *something_uniquegoeshere*;
Sign up to request clarification or add additional context in comments.

Comments

2

Not enough space in a comment unfortunately but here's my advice/suggestion. I'm not certain about your specific error, however in the past I have had issues when re-using variables. You declare your variable outside the for statement and it is possible that this is what is causing the problem.

private void Report4_NeedDataSource(object sender, EventArgs e)
{
  DataTable dt = new DataTable();
  dt = SalesReport.reportDataTable;
  table1.DataSource = dt;

  //Telerik.Reporting.HtmlTextBox textboxGroup; 
  //Telerik.Reporting.HtmlTextBox textBoxTable; 
  table1.ColumnGroups.Clear();
  table1.Body.Columns.Clear();
  table1.Body.Rows.Clear();
  int ColCount = dt.Columns.Count;

  for (int i = 0; i <= ColCount - 1; i++)
  {
    Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
    table1.ColumnGroups.Add(tableGroupColumn);

    var textboxGroup = new Telerik.Reporting.HtmlTextBox();
    textboxGroup.Style.BorderColor.Default = Color.Black;
    textboxGroup.Style.BorderStyle.Default = BorderType.Solid;
    textboxGroup.Value = dt.Columns[i].ColumnName;
    textboxGroup.Size = new SizeU(Unit.Inch(1.5), Unit.Inch(0.6));
    tableGroupColumn.ReportItem = textboxGroup;

    var textBoxTable = new Telerik.Reporting.HtmlTextBox();
    textBoxTable.Value = "=Fields." + dt.Columns[i].ColumnName;
    textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
    table1.Body.SetCellContent(0, i, textBoxTable);

    table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
  }

}

3 Comments

It is changing the Column Header but the data is the same and is of the 1st column
This is the same issue like me telerik.com/forums/data-is-being-duplicated---dynamic-report @talegna
I'm guessing the query is returning the right data, in which case I don't think the binding is working. In my AJAX grids, for example, I've always had to set the data field (can't remember exact word as on mobile ATM) will have a look again and hopefully get back to you if I think I can help further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.