如何在Telerik报告中创建动态表

时间:2014-11-25 13:14:30

标签: telerik report

我需要使用Telerik中的Report中的数据动态创建表及其列。 我正在尝试我创建的表的NeedDataSource事件。 我创建列的代码是:

        Telerik.Reporting.HtmlTextBox textboxGroup;
        Telerik.Reporting.HtmlTextBox textBoxTable;
        this.table1.ColumnGroups.Clear();
        this.table1.Body.Columns.Clear();
        this.table1.Body.Rows.Clear();
        //  int i = 0;
        this.table1.ColumnHeadersPrintOnEveryPage = true;

        int ColCount = dt.Columns.Count;
        for (int j = 1; j <= ColCount - 1; j++)
        {


            var tableGroupColumn = new Telerik.Reporting.TableGroup();
            this.table1.ColumnGroups.Add(tableGroupColumn);
            this.table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(1)));

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

            textBoxTable = new Telerik.Reporting.HtmlTextBox();
            textBoxTable.Style.BorderColor.Default = Color.Black;
            textBoxTable.Style.BorderStyle.Default = BorderType.Solid;
            textBoxTable.Value = "=Fields." + dt.Columns[j].ColumnName;
            textBoxTable.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
            this.table1.Body.SetCellContent(0, j++, textBoxTable);
            this.table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });


        }

表格的标题显示正确,但不显示包含数据信息的行。 任何提示?感谢

1 个答案:

答案 0 :(得分:2)

j必须从0开始,此行必须更正为以下行: this.table1.Body.SetCellContent(0, j ,textBoxTable);

相关问题