Hi All,
I am trying to generate Telerik report with dynamic columns.So I create data table at run time in reporting.So I don't add Datasource in design mode.When I add report to report viewer.This error occurs "Exception has been thrown by the target of an invocation"..
How can I solve this problem.I use the following code in reporting at run time..
private void table1_ItemDataBinding(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
DataTable dtCashBook = new DataTable();
dtCashBook = control.GetCashBookListForReport();
processingTable.DataSource = dtCashBook;
Telerik.Reporting.HtmlTextBox textboxGroup;
Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int i = 0;
foreach (DataColumn dc in dtCashBook.Columns)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
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 = dc.ColumnName.ToString();
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." + dc.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 });
}
}
I am trying to generate Telerik report with dynamic columns.So I create data table at run time in reporting.So I don't add Datasource in design mode.When I add report to report viewer.This error occurs "Exception has been thrown by the target of an invocation"..
How can I solve this problem.I use the following code in reporting at run time..
private void table1_ItemDataBinding(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
DataTable dtCashBook = new DataTable();
dtCashBook = control.GetCashBookListForReport();
processingTable.DataSource = dtCashBook;
Telerik.Reporting.HtmlTextBox textboxGroup;
Telerik.Reporting.HtmlTextBox textBoxTable;
table1.ColumnGroups.Clear();
table1.Body.Columns.Clear();
table1.Body.Rows.Clear();
int i = 0;
foreach (DataColumn dc in dtCashBook.Columns)
{
Telerik.Reporting.TableGroup tableGroupColumn = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(tableGroupColumn);
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 = dc.ColumnName.ToString();
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." + dc.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 });
}
}