Telerik 报告显示动态创建的所有列的相同数据 [英] Telerik report showing same data for all columns created dynamically

查看:28
本文介绍了Telerik 报告显示动态创建的所有列的相同数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual Studio 创建了一个 Telerik 报告,并从 DataTable 设置了数据源.我在运行时使用 Telerik.Reporting.TableGroup 动态创建列.现在我在这里遇到的问题是报告显示所有字段的相同数据,并且在我调试时它为不同的字段设置不同的字段.

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.

我使用的代码如下:

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 });

  }

}

推荐答案

很遗憾,评论中没有足够的空间,但这是我的建议/建议.我不确定您的具体错误,但是过去我在重用变量时遇到了问题.您在 for 语句之外声明变量,这可能是导致问题的原因.

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 });
  }

}

这篇关于Telerik 报告显示动态创建的所有列的相同数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆