我正在尝试动态生成 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 列不显示价格,尽管是从数据存储中检索的,并且可以在上面的数据表图片中看到。
我已经逐行跟踪代码,并且可以在跟踪代码时找出价格。但我不知道为什么它们没有显示在浏览器中。
希望有人能帮帮我,非常感谢