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

Dynamic table is empty

3 Answers 231 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
veena
Top achievements
Rank 1
veena asked on 11 May 2011, 07:44 PM
I have added a report and table dynamically, my dataset has 10 rows but when the report renders, it has just header, no data is rendered
I used the AutoGenerateColumns project

Here is the code

public void RenderReport()
        {
            Telerik.Reporting.Report report1 = new Telerik.Reporting.Report();
            //report1.DataSource = DataSource;

            styleRule = new Telerik.Reporting.Drawing.StyleRule();
            //Add a TypeSelector
            styleRule.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] { new Telerik.Reporting.Drawing.TypeSelector(typeof(Telerik.Reporting.TextBox)), new Telerik.Reporting.Drawing.TypeSelector(typeof(Telerik.Reporting.HtmlTextBox)) });
            //Add formatting
            styleRule.Style.Font.Name = "Courier New";
            styleRule.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Inch(.5);
            //Add rule to Style Sheet
            report1.StyleSheet.AddRange(new Telerik.Reporting.Drawing.StyleRule[] { styleRule });

            table1  = new Telerik.Reporting.Table();
            table1.ColumnHeadersPrintOnEveryPage = true;
            table1.ColumnGroups.Clear();
            table1.Body.Columns.Clear();
            table1.Body.Rows.Clear();
            table1.DataSource = DataSource;
            table1.ItemDataBinding += new EventHandler(table_ItemDataBinding);

            string sortCol = "";
            string sortDir = "";
            if (SortDescriptors.Count > 0)
            {
                ColumnSortDescriptor sd = SortDescriptors[0] as ColumnSortDescriptor;
                sortCol = sd.Column.UniqueName;
                sortDir = sd.SortDirection.ToString();
            }
            //Page Header Section
            Telerik.Reporting.PageHeaderSection pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();
            if (ShowPageHeader)
            {
                pageHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
                pageHeaderSection1.Style.BackgroundColor = Color.Gray;
                Telerik.Reporting.TextBox txtHead = new Telerik.Reporting.TextBox();
                txtHead.Value = "Title";
                txtHead.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(3.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
                txtHead.Name = "reportTitle";
                txtHead.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
                pageHeaderSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtHead });
            }
            int count = ColumnCollection.Where(p => p.ColIsVisible == true).Count();

            Telerik.Reporting.Drawing.Unit x = Telerik.Reporting.Drawing.Unit.Inch(0);
            Telerik.Reporting.Drawing.Unit y = Telerik.Reporting.Drawing.Unit.Inch(0);

            Telerik.Reporting.ReportItemBase[] headColumnList = new Telerik.Reporting.ReportItem[count];
            Telerik.Reporting.ReportItemBase[] detailColumnList = new Telerik.Reporting.ReportItem[count];

            Telerik.Reporting.Group group = new Telerik.Reporting.Group();

 

            Telerik.Reporting.ReportItemBase[] groupColumnList = new Telerik.Reporting.ReportItem[GroupDescriptor.Count];
            int i = GroupDescriptor.Count;
            if (GroupDescriptor.Count > 0)
            {
                Telerik.Reporting.GroupHeaderSection groupHeaderSection1 = new Telerik.Reporting.GroupHeaderSection();
                foreach (ColumnGroupDescriptor grpDescriptor in GroupDescriptor)
                {
                    string grpCol = grpDescriptor.Column.UniqueName;
                    group.Groupings.Add(new Telerik.Reporting.Data.Grouping("=Fields." + grpCol));
                    if (grpDescriptor.SortDirection.ToString().ToLower() == "descending")
                    {
                        group.Sortings.Add(new Telerik.Reporting.Data.Sorting("=Fields." + grpCol, Telerik.Reporting.Data.SortDirection.Desc));
                    }
                    else
                    {
                        group.Sortings.Add(new Telerik.Reporting.Data.Sorting("=Fields." + grpCol, Telerik.Reporting.Data.SortDirection.Asc));
                    }
                    i--;
                    Telerik.Reporting.TextBox hdCol = new Telerik.Reporting.TextBox();
                    hdCol.Style.BackgroundColor = Color.Orange;
                    hdCol.Style.BorderStyle.Default = BorderType.Solid;
                    hdCol.Style.BorderWidth.Default = Unit.Pixel(1);
                    hdCol.KeepTogether = true;
                    hdCol.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
                    hdCol.Value = "=[" + grpCol + "]"; ;
                    groupColumnList[i] = hdCol;
                    group.GroupHeader = groupHeaderSection1;
                    group.GroupHeader.Height = Telerik.Reporting.Drawing.Unit.Inch(0);

                }
                groupHeaderSection1.Items.AddRange(groupColumnList);
            }

            if (sortCol.Length > 0)
            {
                group.Groupings.Add(new Telerik.Reporting.Data.Grouping("=Fields." + sortCol));
                if (sortDir.ToLower() == "descending")
                {
                    group.Sortings.Add(new Telerik.Reporting.Data.Sorting("=Fields." + sortCol, Telerik.Reporting.Data.SortDirection.Desc));
                }
                else
                {
                    group.Sortings.Add(new Telerik.Reporting.Data.Sorting("=Fields." + sortCol, Telerik.Reporting.Data.SortDirection.Asc));
                }
            }

 

            //Detail Section
            Telerik.Reporting.DetailSection detailSection1 = new Telerik.Reporting.DetailSection();
            detailSection1.Height = new Telerik.Reporting.Drawing.Unit(2D, Telerik.Reporting.Drawing.UnitType.Inch);
            detailSection1.Items.AddRange(new ReportItemBase[] { table1 });

 

            //Page Footer Section
            Telerik.Reporting.PageFooterSection pageFooterSection1 = new Telerik.Reporting.PageFooterSection();
            if (ShowPageFooter)
            {
                pageFooterSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
                pageFooterSection1.Style.BackgroundColor = Color.LightGray;
                pageFooterSection1.PrintOnFirstPage = true;
                pageFooterSection1.PrintOnLastPage = true;
                Telerik.Reporting.TextBox txtFooter = new Telerik.Reporting.TextBox();
                if (ShowPageNumber)
                {
                    txtFooter.Value = "='Page ' + PageNumber + ' of ' + PageCount";
                    txtFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(4.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
                    txtFooter.Name = "pageInfoTextBox";
                    txtFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch)); //new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))));
                }
                Telerik.Reporting.PictureBox picBoxFooter = new Telerik.Reporting.PictureBox();
                picBoxFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(5.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
                picBoxFooter.Value = @"C:\CCMSGoldStandard_Local\CCMSGoldStandard\CCMSAppShell\Images\no.png";
                picBoxFooter.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
                picBoxFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(.5D, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))));
                picBoxFooter.Sizing = ImageSizeMode.AutoSize;

                pageFooterSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtFooter, picBoxFooter });
            }
            //add all section to report
            report1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { pageHeaderSection1, detailSection1, pageFooterSection1 });

            report1.PageSettings.Landscape = false;
            report1.PageSettings.Margins.Bottom = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Left = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Right = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Top = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);
            Telerik.Reporting.Drawing.SizeU paperSize = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(25, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch));
            report1.PageSettings.PaperSize = paperSize;
            report1.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Custom;

            Hashtable deviceInfo = new Hashtable();
            deviceInfo["FontEmbedding"] = "Subset";
            if (ExportType.ToLower() == "csv")
            {
                deviceInfo["NoHeader"] = true;
                deviceInfo["NoStaticText"] = true;
            }
            ExportType = ExportType == "rtf" ? "docx" : ExportType;
            Telerik.Reporting.Processing.ReportProcessor RP = new Telerik.Reporting.Processing.ReportProcessor();
            byte[] buffer = RP.RenderReport(ExportType.ToUpper(), report1, deviceInfo).DocumentBytes;

            string myPath = "C:";
            string file = myPath + @"\" + DateTime.Now.ToString("HHmmss") + "." + ExportType;
            FileStream fs = new FileStream(file, FileMode.Create);

            fs.Write(buffer, 0, buffer.Length);
            fs.Flush();
            fs.Close();

            Process.Start(file);
        }

        void table_ItemDataBinding(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Table processingTable = (sender as Telerik.Reporting.Processing.Table);
            processingTable.DataSource = DataSource;
            int count = ColumnCollection.Where(p => p.ColIsVisible == true).Count();
            Telerik.Reporting.HtmlTextBox headerCol;
            Telerik.Reporting.TextBox textBox;

            int column = 0;
            foreach (GridViewData.columnData info in ColumnCollection)
            {
                if (info.ColIsVisible)
                {
                    TableGroup tableGroupColumn = new TableGroup();
                    table1.ColumnGroups.Add(tableGroupColumn);
                    table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(new Telerik.Reporting.Drawing.Unit(2D, Telerik.Reporting.Drawing.UnitType.Inch)));

                    string columnName = info.ColHeader;
                    headerCol = CreateTxtHeader(columnName, column);
                    headerCol.Style.BackgroundColor = Color.LemonChiffon;
                    headerCol.Style.BorderStyle.Default = BorderType.Solid;
                    headerCol.Style.BorderWidth.Default = Unit.Pixel(1);
                    headerCol.Size = new SizeU(Unit.Inch(3.5), Unit.Inch(0.3));
                    tableGroupColumn.ReportItem = headerCol;

                    textBox = CreateTxtDetail(info.ColDataMemberBinding, column);
                    textBox.Style.BorderStyle.Default = BorderType.Solid;
                    textBox.Style.BorderWidth.Default = Unit.Pixel(1);
                    textBox.CanGrow = true;
                    textBox.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3));
                    column++;
                    table1.Body.SetCellContent(0, column, textBox);
                    table1.Items.AddRange(new ReportItemBase[] { textBox, headerCol });

                }
            }

        }

        static void textBox_ItemDataBound(object sender, EventArgs e)
        {

            if (((Telerik.Reporting.Processing.TextBox)sender).Value == null || (((Telerik.Reporting.Processing.TextBox)sender).Value.ToString() == ""))
            {
                ((Telerik.Reporting.Processing.TextBox)sender).Value = "";
            }

        }

        public static Telerik.Reporting.HtmlTextBox CreateTxtHeader(string FieldName, int i)
        {

            Telerik.Reporting.HtmlTextBox txtHead = new Telerik.Reporting.HtmlTextBox();
            txtHead.Value = FieldName;
            return txtHead;
        }

        public static Telerik.Reporting.HtmlTextBox CreateHTMLTxtDetail(string FieldName, int i)
        {

            Telerik.Reporting.HtmlTextBox txtHead = new Telerik.Reporting.HtmlTextBox();
            txtHead.Value = "=[" + FieldName + "]";
            //txtHead.Dock = DockStyle.Left;
            //txtHead.Name = FieldName;
            txtHead.CanGrow = true;
            return txtHead;
        }

        public static Telerik.Reporting.TextBox CreateTxtDetail(string FieldName, int i)
        {

            Telerik.Reporting.TextBox txtHead = new Telerik.Reporting.TextBox();
            txtHead.Value = "=Fields." + FieldName + "";
            txtHead.Name = FieldName;
            txtHead.TextWrap = true;
       
            //txtHead.Dock = DockStyle.Left;
            //txtHead.CanGrow = true;
            return txtHead;
        }

    }

 

 

3 Answers, 1 is accepted

Sort by
0
veena
Top achievements
Rank 1
answered on 12 May 2011, 03:43 AM
I figured out the issue.

I needed to add dummy TableGroup in my renderReport method as below..

tableGroup1 = new Telerik.Reporting.TableGroup();
            tableGroup1.Groupings.AddRange(new Telerik.Reporting.Data.Grouping[] {
            new Telerik.Reporting.Data.Grouping("")});
            tableGroup1.Name = "DetailGroup";
            table1.RowGroups.Add(tableGroup1);
0
Arun Thiagu
Top achievements
Rank 1
answered on 14 May 2011, 05:00 PM
Hi,
    i dont know create a dynamic report in telerick , can u send a soruce code with one grouping

table like empid,empname,salary,dept

group by dept


Advance Thanks
Arun T



 


 
0
veena
Top achievements
Rank 1
answered on 16 May 2011, 08:30 PM

Your requirement is easy,

create a table with four columns for header and four for data. As I have specified in post before

report1.DataSource = ReportDataSource;


Create GroupHeader as

string grpCol = "Dept";

 

Telerik.Reporting.Group group = new Telerik.Reporting.Group();

 

 

group.Name =

 

"Group" + grpCol;

 

 

Telerik.Reporting.

 

GroupHeaderSection groupHeader = new Telerik.Reporting.GroupHeaderSection();

 

 

groupHeader.Name =

 

"GroupHeader" + grpCol;

 

 

groupHeader.Height = uHeight;

 

group.GroupHeader = groupHeader;

 

groupHeader.PrintOnEveryPage =

 

true;

 

 

groupHeader.Visible =

 

true;

 

 

groupHeader.KeepTogether =

 

true;

 

 

 

 

Telerik.Reporting.

 

TextBox hdCol = new Telerik.Reporting.TextBox();

 

 

hdCol.Style.BackgroundColor =

 

Color.Orange;

 

 

hdCol.Style.BorderStyle.Default =

 

BorderType.Solid;

 

 

hdCol.Style.BorderWidth.Default =

 

Unit.Pixel(1);

 

 

hdCol.KeepTogether =

 

true;

 

 

hdCol.Size =

 

new Telerik.Reporting.Drawing.SizeU(uWidth, uHeight);

 

 

hdCol.Value =

 

"=Fields." + grpCol;

 

 

 

 

group.GroupHeader = groupHeader;

 

group.Groupings.AddRange(

 

new Telerik.Reporting.Data.Grouping[] {new Telerik.Reporting.Data.Grouping("=Fields." + grpCol)});

 

 

 

 

if (grpDescriptor.Column.SortingState == Telerik.Windows.Controls.SortingState.Descending)

 

 

{

 

group.Sortings.AddRange(

 

new Telerik.Reporting.Data.Sorting[] { new Telerik.Reporting.Data.Sorting("=Fields." + grpCol, Telerik.Reporting.Data.SortDirection.Desc) });

 

 

}

 

 

 

else

 

 

{

 

group.Sortings.AddRange(

 

new Telerik.Reporting.Data.Sorting[] { new Telerik.Reporting.Data.Sorting("=Fields." + grpCol, Telerik.Reporting.Data.SortDirection.Asc) });

 

 

}

groupHeader.Items.AddRange(

new Telerik.Reporting.ReportItemBase[] { hdCol, table1 });

 

Telerik.Reporting.Data.Filter filter = new Telerik.Reporting.Data.Filter("=Fields." + grpCol, Telerik.Reporting.Data.FilterOperator.Equal, "= ReportItem.Parent.DataObject." + grpCol);

 

 

table1.Filters.Add(filter);

//this is important step

report1.DataSource = ReportDataSource;

 

report1.Groups.AddRange(new Telerik.Reporting.Group[]{group});

 

detailSection1.Visible = false;

 

 

 

 

 

report1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { pageHeaderSection1, detailSection1,groupHeader,pageFooterSection1  });

My code is pure dynamic, I have nothing specified columnName, groupingcolumns or sorting. So it will probably confuse you. But if you still want i can send you. I finished up with multi level grouping, last glitch is last level group header is not displayed. Not sure if is it is how it meant to work, since data is grouped appropriately.

 

 

 

 

Tags
General Discussions
Asked by
veena
Top achievements
Rank 1
Answers by
veena
Top achievements
Rank 1
Arun Thiagu
Top achievements
Rank 1
Share this question
or