【问题标题】:Generating Table in Telerik Report Viewer Programmatically以编程方式在 Telerik Report Viewer 中生成表格
【发布时间】:2013-07-23 05:05:12
【问题描述】:

我正在尝试动态生成 Telerik 报告表。实际上,除了上网之外,经过大量的努力,我得到了以下代码,它工作正常,但没有呈现所需的输出。代码如下:

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

这是一张包含表格数据的DataTable图片:

最后,当然不是当前需要的输出:

所以问题是: Account_Price 列不显示价格,虽然是从数据存储中检索的,并且可以在上面的数据表图片中看到。

我已经逐行跟踪代码,并且可以通过跟踪代码找出价格。但我不知道为什么它们没有显示在浏览器中。

希望有人可以帮助我, 非常感谢

【问题讨论】:

    标签: c# asp.net-mvc telerik telerik-reporting


    【解决方案1】:

    显然,这是后来 Telerik 报告的新问题。

    我在 Telerik 论坛中找到了答案: http://www.telerik.com/community/forums/reporting/telerik-reporting/incorrect-dynamic-table-columns.aspx

    基本上,您需要为 TableGroup 列分配一个唯一的名称:

    TableGroup tableGroupColumn = new TableGroup();
    //add this :
    tableGroupColumn.Name = i.ToString();
    

    【讨论】:

    • 您提供的链接重定向到此页面。
    • 奇怪,不知道发生了什么,但我编辑了链接以指向 Telerik 论坛。
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 2010-11-18
    • 2023-01-13
    相关资源
    最近更新 更多