首页 文章

以编程方式在Telerik Report Viewer中生成表

提问于
浏览
0

我正在尝试动态生成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的图片,其中包含表数据:

Data Table Image of the Report

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

Report Result (Not Desired)

So the problem is; Account_Price列不显示价格,但从数据存储中检索,可以在上面的数据表图片中看到 .

我已经逐行跟踪代码,可以找出跟踪代码的价格 . 但我不知道他们为什么没有在浏览器中显示 .

希望任何人都可以帮助我,非常感谢你

1 回答

相关问题