2014-11-25 41 views
1

我需要在Telerik中的Report中动态创建表格及其列。 我正在尝试创建的表的NeedDataSource事件。 我的代码来创建列是:如何在Telerik报表中动态创建表格

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


     } 

的表的首部示出正确,但不与数据信息的行。 任何提示?感谢

回答

2

Ĵ必须在0开始并且该线必须被校正为下列行: this.table1.Body.SetCellContent(0,Ĵ,textBoxTable);

+0

是的,你是对的,我在几个月前做过。谢谢 – Suminch 2015-07-29 11:54:00