This is a migrated thread and some comments may be shown as answers.

I use dynamic table for Telerik Report porpose.

8 Answers 1018 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chief
Top achievements
Rank 1
Chief asked on 19 Jan 2011, 12:24 PM

I  use dynamic table for Telerik Report porpose.I already created Telerik Report but when I use Dataset I can not show the fields of table How can I show the values of Dataset in report. 
Note : I did not define any field in design section because I do not know it and also Dataset is not empty

Since my T-SQL is dynamic, i can not assign fields to tables at the report design. I wonder how i can assign fields ?  


my code is as follow;

private void rpt_MPDlist_NeedDataSource(object sender, EventArgs e)
        {
            SqlConnection connSomsys = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
            SqlCommand selectCurrentYearTot;
            selectCurrentYearTot = new SqlCommand("CNF_MPDRelatedModList_search",connSomsys); 
            selectCurrentYearTot.CommandType = CommandType.StoredProcedure;
             selectCurrentYearTot.Parameters.AddWithValue("@table", this.ReportParameters["table"].Value);
            SqlDataAdapter adapter2 = new SqlDataAdapter(selectCurrentYearTot);
            DataSet ds = new DataSet();
            adapter2.Fill(ds); 
            table1.DataSource = ds;

        }

T-SQL code;

CREATE procedure CNF_MPDRelatedModList_search 
(     
 @table as nvarchar (200)   
)     
AS          
BEGIN      
 declare   @filename as nvarchar (400)     
 declare @sql as nvarchar (4000)     
 set @filename=@table     
      declare @deneme as nvarchar (4000)     
      set @deneme='2'   
set @SQL = replace(replace('select ATA_SB_NO,TITLE,MOD_NO,MP_NO,COMPLIANCE,EO_NO,NOTES from (SELECT ATA_SB_NO,TITLE,MOD_NO,cast (len (MOD_NO)as int) MD,MP_NO,cast (len (MP_NO) as int) MP,COMPLIANCE,EO_NO,NOTES FROM @filename  )mst where MP >@deneme  and M
D >@deneme' ,'@filename', @filename ),'@deneme',@deneme )                                    
            exec sp_executesql @SQL          
                     
END 


8 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 24 Jan 2011, 02:39 PM
Hello bülent,

The Table item is a Data Item so it requires a data source to be set and also it requires a definition (assign fields and set up groups). The referenced help section about the Table item covers its structure and basic concepts, so I highly recommend reviewing those, but I would nevertheless try to list them here in brief.

Telerik Reporting's Table item is built on a concept different than the regular grid components. While the grids are usually based on the rows and columns abstraction and display dynamic data by rows, the Telerik Reporting's Table item can display dynamic data by rows and/or columns that extends greatly the flexibility of the report.

As you have already noticed the most important part of the Table item (the Table, the Crosstab and the List items are actually the same Table item with different initial settings) are the Row and Column group hierarchies. The groups in the RowGroups hierarchy define rules how the rows of the Table will be repeated, while the groups in the ColumnGroups hierarchy are responsible for the columns. So the leaf groups in the RowGroups (leaf group has no child groups) defines the rows in the Table Body while the leaf column groups define the columns of the Table Body.

Depending on the grouping criteria, we have:

  • dynamic groups - have any Grouping expression, ex. group1.Grouping.Add(new Grouping("=Fields.Country")). For the dynamic groups, the corresponding row/column will repeat for every record of the grouped data.
  • static groups - no grouping criteria at all. For the static groups the corresponding row/column is rendered only once.
  • detail groups -have a single empty grouping, ex. group1.Grouping.Add(new Grouping()). Usually you have only one row -or- column detail group. For a detail group the corresponding row/column is repeated for every row of the Table's data source. You may think of the detail TableGroup as the Report's Detail section.

Since we have Row and Column group hierarchies this means that one group may contain one or more child groups and you may have one or more root groups.

Depending on the configuration you may create:

  • a simple static grid for ordering items by rows/columns. Use only static groups for the rows and columns.
  • regular (vertical) table -  the data records are displayed by rows. Define one detail group for the Row hierarchy and static column groups to define the columns.
  • master-detail table - define one or more levels of nested row groups and if needed add a detail group to the end: [County] - [City] - [Detail]
  • horizontal table - the data records are rendered by columns. Define one detail column group and put some static row groups to define the Table Body's rows.
  • cross table/pivot table - Define dynamic groups in both Rows and Columns hierarchies; use aggregates for the body cells.

Having the above in mind, we highly recommend creating the desired table through the Report Designer first and then review the code in the InitializeComponent to see the internal structure.
Eitherway I've attached a sample project showing you how to create a dynamic table based on the data source columns. 

Regards,
Peter
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Mahendra
Top achievements
Rank 1
answered on 15 Feb 2011, 02:13 PM
Hi,

How can we add dynamic RowGroups in auto generated column.
I have written the code like
  this.table1.RowGroups.Clear();
            Telerik.Reporting.TableGroup group1 = new Telerik.Reporting.TableGroup();
            group1.Groupings.Add(new Telerik.Reporting.Data.Grouping("=Fields.State"));
            group1.Sortings.Add(new Telerik.Reporting.Data.Sorting("=Fields.State", Telerik.Reporting.Data.SortDirection.Asc));
            Telerik.Reporting.TextBox textBox1 = new Telerik.Reporting.TextBox();
            table1.Items.Add(textBox1);
            group1.ReportItem = textBox1;
            table1.RowGroups.Add(group1);


But its giving me object reference error.
0
Peter
Telerik team
answered on 17 Feb 2011, 02:59 PM
Hi Mahendra,

The provided error is generic one and doesn't give us enough information. Generally a table Row Group needs a detail group as a child. Another thing we have noticed in the provided code is that you have ommited the Group.Name properties that are obligatory.
tableGroup3.Groupings.AddRange(new Telerik.Reporting.Data.Grouping[] {
new Telerik.Reporting.Data.Grouping("")});
tableGroup3.Name = "Detail";

tableGroup2.ChildGroups.Add(tableGroup3);

tableGroup2.Groupings.AddRange(new Telerik.Reporting.Data.Grouping[] {
new Telerik.Reporting.Data.Grouping("=Fields.Manufacturer")});

tableGroup2.Name = "Manufacturer";

tableGroup2.ReportItem = this.textBox2;
tableGroup2.Sortings.AddRange(new Telerik.Reporting.Data.Sorting[] {
new Telerik.Reporting.Data.Sorting("=Fields.Manufacturer", Telerik.Reporting.Data.SortDirection.Asc)});
this.crosstab1.RowGroups.Add(tableGroup2);
this.crosstab1.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1.6000000238418579D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.40000000596046448D, Telerik.Reporting.Drawing.UnitType.Inch));
this.crosstab1.StyleName = "Normal.TableNormal";

In general we highly recommend creating the desired table through the Report Designer first and then review the code in the InitializeComponent to see the internal structure.

Kind regards,
Peter
the Telerik team
0
Vijetha
Top achievements
Rank 1
answered on 15 Nov 2011, 09:21 AM
Hi telerik
i tried the sample code which you have provided in AutoGenerateColumns.zip it works for me file. In addition to this i want to add a static row to the table as the header row. I tries as following

           TableBodyRow row = new TableBodyRow(new Telerik.Reporting.Drawing.Unit(0.2, Telerik.Reporting.Drawing.UnitType.Inch));
            rptTable.Body.Rows.Add(row);
            Telerik.Reporting.TextBox txt = new TextBox();
            txt.Size = currentCellWidth1;
            txt.Value = "Vijetha";
            rptTable.Body.SetCellContent(0, 0, txt);

but it does not work for me. please suggest how to add static row for table which i have attached in the image .marked with the red color text there i want to add a static row.

0
Peter
Telerik team
answered on 18 Nov 2011, 10:00 AM
Hi Vijetha,

In order to add a new header row, you have to setup a TableGroup and add it as child to the current one. I have updated the sample project.

Best wishes,
Peter
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

0
Randhir
Top achievements
Rank 1
answered on 04 Sep 2013, 10:10 AM
I have user Q1 2013 version i have used below code for dynamically column displayed in the table but getting error

private void table1_ItemDataBinding(object sender, EventArgs e)
        {
           // get the processing table object since we're in the context of event
            Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);

            FilterValues objFilrs = new FilterValues();

            objFilrs = (FilterValues)HttpContext.Current.Session["filterVal"];
            DataSet ds=new DataSet();
            DataTable dt=new DataTable();
            ds = ImportHistoryBIZ.GetImportHistSearch(objFilrs);
            dt = ds.Tables[1];
            dt = (DataTable)HttpContext.Current.Session["filterVal"];
            processingTable.DataSource = dt;

            //create two HtmlTextBox items (one for header and one for data) which would be added to the items collection of the table
            Telerik.Reporting.HtmlTextBox textboxGroup;
            Telerik.Reporting.HtmlTextBox textBoxTable;

            //we do not clear the Rows collection, since we have a details row group and need to create columns only
            this.table1.ColumnGroups.Clear();
            this.table1.Body.Columns.Clear();
            this.table1.Body.Rows.Clear();
            int i = 0;
            this.table1.ColumnHeadersPrintOnEveryPage = true;
            foreach (DataColumn dc in dt.Columns)
            {
                Telerik.Reporting.TableGroup 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 = 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));
                this.table1.Body.SetCellContent(0, i++, textBoxTable);
                this.table1.Items.AddRange(new ReportItemBase[] { textBoxTable, textboxGroup });
            }
        }

Please suggest me...
0
Squall
Top achievements
Rank 1
answered on 04 Sep 2013, 01:48 PM
What is the error? I noticed that you have omitted to set the report objects Name property. The Name property is compulsory for all report objects.
0
Jesse Flint
Top achievements
Rank 1
answered on 17 Feb 2014, 06:36 PM
Id just like to say +1 for this post.. I'm not sure if he got his problem resolved or not, but his code example really helped me solve the issue of programmatically creating a table with the header definitions etc.  The UI designer code is nice, but this helped me make sense of what to do in a loop condition with the add range and text box assignments.   Thanks for posting this..
Tags
General Discussions
Asked by
Chief
Top achievements
Rank 1
Answers by
Peter
Telerik team
Mahendra
Top achievements
Rank 1
Vijetha
Top achievements
Rank 1
Randhir
Top achievements
Rank 1
Squall
Top achievements
Rank 1
Jesse Flint
Top achievements
Rank 1
Share this question
or