Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am Kuldeep, trying to create dynamic report thru this code but show blank.
Please help or suggest me, what I am making mistake in it. Is it right code? And where I can find its solution or help.
C#
private void table1_ItemDataBinding(object sender, EventArgs e)
        {
            dbCon = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
            dbCon.Open();
            dbCon.Close();
            SqlDataAdapter adapter = new SqlDataAdapter("spOrder", dbCon);
            Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
            Telerik.Reporting.Table table1 = new Telerik.Reporting.Table();
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            processingTable.DataSource = dt;
            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 dt.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 });

            }
        }

Thanks and Regards!
Kuldeep Dwivedi
Posted
Updated 30-Aug-11 17:17pm
v3
Comments
Prerak Patel 30-Aug-11 23:17pm    
Use code block for code segments in question.

Thanks RaisKazi

Problem is solved.
Please find the solution steps with code and if there is any idea to make it is or more meaningful please suggest me. Below code is working for me.
1. Drag a blank table on report first.
2. Code behind:-
C#
private void ReportTry_NeedDataSource(object sender, EventArgs e)
        {
            dbCon = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
            dbCon.Open();
            dbCon.Close();
            SqlDataAdapter adapter = new SqlDataAdapter("spOrder", dbCon);
           
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            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);
                //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[i].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[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 });
            
            }
           
        }
Thanks and Reagdrs!
Kuldeep Dwivedi
 
Share this answer
 
v2
Comments
RaisKazi 31-Aug-11 9:13am    
Perfect 5! Glad to see you solved this by your own. Formatted your Answer, for the reference of other users.
ajesuraj 15-Oct-13 21:29pm    
the above solution is not working.
if i use table.Datasource=dt then
An error has occurred while processing Table 'table3': Missing operator before 'experience' operand.

if i use lerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
Telerik.Reporting.Table table3 = new Telerik.Reporting.Table();
processingTable.DataSource = dt;

then empty report shows.but dt contains all data.
Can anyone give solution.
lufega1986 23-Jan-12 12:16pm    
I have a probem when the data show the error is 'An error has ocurred while processing HtmlTextBox', because datatable contains special caracter How &,',´¨ an etc;
How I could be solve this?
Víctor Sumozas 25-Nov-14 11:27am    
This solution 2 is still not working. Any other solution?
Telerik Support Forum may provide you solution on this, if you are a registerd Telerik User.

TELERIK SUPPORT FORUMS
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900