2014-07-11 44 views
0

我已經使用Visual Studio創建了一個telerik報告並從DataTable設置了數據源。我使用Telerik.Reporting.TableGroup在運行時動態創建列。現在我在這裏遇到的問題是報告顯示所有字段的相同數據,並且當我調試它時,會爲不同的字段設置不同的字段。Telerik報告顯示動態創建的所有列的相同數據

我使用的代碼如下:

在評論
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 }); 

    } 

} 

回答

1

沒有足夠的空間,但不幸的是這裏是我的建議/建議。我不確定您的具體錯誤,但是在過去,我在重新使用變量時遇到了問題。您在for語句之外聲明您的變量,這可能是導致問題的原因。

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

} 
+0

仍然沒有工作 – Nosheen

+0

它改變了列標題,但數據是相同的,並且是第一列 – Nosheen

+0

這是像我一樣的問題的http://www.telerik.com/forums/data-is-being-duplicated --- dynamic-report @talegna – Nosheen

2

我建議閱讀以下文章。我發現了同樣的問題,我的解決方案是爲組列,標籤和詳細信息文本框添加唯一的名稱。

http://www.telerik.com/forums/incorrect-dynamic-table-columns

//Added 
tableGroupColumn.Name = "group" + *something_uniquegoeshere*; 

//Added 
textboxGroup.Name = "label" + *something_uniquegoeshere*; 

//Added 
textBoxTable.Name = "data" + *something_uniquegoeshere*; 
+0

謝謝!這爲我修好了。 –