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

Dynamic Grid inside a FormView Item Template

2 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Payal Mandalia
Top achievements
Rank 1
Payal Mandalia asked on 16 Apr 2010, 06:45 AM
Hi all,

I have been using RadControls for a while now and I really like them.But this dynamic Grid creation is driving me crazy.

Basically I have a page to generate dynamic reports and I am using Radgrid in a FormView to view report.
I have my grid statically declared in the markup and I create the mastertableview columns and detailtableview columns at runtime from code behind and it can have as many hierarchy level the user wants.The hierarchy mode is ServerBind.
I create the structure and properties on PageLoad.

Now the problem I am facing is I am not able to expand the detailtableview and cant navigate to the next page of the grid..
I have tried everyhting possible but cant figure wht the problem is??/
If anyone could help me with this issue it would be great...

The error im getting is : System.Data.SyntaxErrorException: Syntax error: Missing operand before 'Is' operator.
The stack trace looks like this:
[SyntaxErrorException: Syntax error: Missing operand before 'Is' operator.]
   System.Data.ExpressionParser.Parse() +6215852
   System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +154
   System.Data.DataView.set_RowFilter(String value) +188
   System.Data.LinqDataView.set_RowFilter(String value) +63
   Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +3800
   Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +24
   Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray) +164
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +514
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +625
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +72
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +147
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +261
   Telerik.Web.UI.GridTableView.PerformSelect() +9
   Telerik.Web.UI.GridTableView.DataBind() +363
   Telerik.Web.UI.GridDataItem.OnExpand() +474
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +185
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +54
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +142
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
#region Declarations and Initializations  
 
            //Create Dataclasscontext object  
            DataClassesDataContext dbcontext = new DataClassesDataContext();
          
            #region Column Info Class  
 
            //Class to hold the data of ReportColumns   
            public class colInfo  
            {  
                protected int ID;  
                protected int? reportColumnID;  
                protected int? reportID;  
                protected string tableName;  
                protected string columnName;  
                protected int? reportTableHeirarchyID;  
                protected string heading;  
                protected string description;  
                protected bool filterable;  
                protected int reportColumnTypeID;  
                protected string columnType;  
                protected string dataFormatString;  
                protected string dataType;  
                protected string emptyDataText;  
                protected bool allowFiltering;  
                protected bool allowSorting;  
                protected bool showFilterIcon;  
                protected bool showSortIcon;  
                protected string headerStyleWidth;  
                protected string aggregate;  
                protected string sortExpression;  
                protected string dataField;  
                protected string footerAggregateFormatString;  
                protected bool activeColumn;  
                protected bool removed;  
                protected DateTime? purgeDate;  
                protected int userCreatedID;  
                protected int userModifiedID;  
                protected DateTime Created;  
                protected DateTime Modified;  
 
                public colInfo(int nID, int? nreportColumnID, int? nreportID, string ntable, string ncolumnName, int? nreportTableHeirarchyID, string nheading, string ndescription,  
                               bool nfilterable, int nreportColumnTypeID, string ncolumnType, string ndataType, string ndataFormatString, string nemptyDataText,  
                               bool nallowFiltering, bool nallowSorting, bool nshowFilterIcon, bool nshowSortIcon, string nheaderStyleWidth, string naggregate,  
                               string nsortExpression, string ndataField, string nfooterAggregateFormatString, bool nactive, bool nremoved, DateTime? npurgeDate,  
                               int nuserCreatedID, int nuserModifiedID, DateTime nCreated, DateTime nModified)  
                {  
                    ID = nID;  
                    reportColumnID = nreportColumnID;  
                    reportID = nreportID;  
                    tableName = ntable;  
                    columnName = ncolumnName;  
                    reportTableHeirarchyID = nreportTableHeirarchyID;  
                    heading = nheading;  
                    description = ndescription;  
                    filterable = nfilterable;  
                    reportColumnTypeID = nreportColumnTypeID;  
                    columnType = ncolumnType;  
                    dataFormatString = ndataFormatString;  
                    dataType = ndataType;  
                    emptyDataText = nemptyDataText;  
                    allowFiltering = nallowFiltering;  
                    allowSorting = nallowSorting;  
                    showFilterIcon = nshowFilterIcon;  
                    showSortIcon = nshowSortIcon;  
                    headerStyleWidth = nheaderStyleWidth;  
                    aggregate = naggregate;  
                    sortExpression = nsortExpression;  
                    dataField = ndataField;  
                    footerAggregateFormatString = nfooterAggregateFormatString;  
                    activeColumn = nactive;  
                    removed = nremoved;  
                    purgeDate = npurgeDate;  
                    userCreatedID = nuserCreatedID;  
                    userModifiedID = nuserModifiedID;  
                    Created = nCreated;  
                    Modified = nModified;  
                }  
 
                public int Id  
                {  
                    get 
                    {  
                        return ID;  
                    }  
                    set 
                    {  
                        ID = value;  
                    }  
                }  
                public int? ReportColumnId  
                {  
                    get 
                    {  
                        return reportColumnID;  
                    }  
                    set 
                    {  
                        reportColumnID = value;  
                    }  
                }  
                public int? ReportId  
                {  
                    get 
                    {  
                        return reportID;  
                    }  
                    set 
                    {  
                        reportID = value;  
                    }  
                }  
                public string TableName  
                {  
                    get 
                    {  
                        return tableName;  
                    }  
                    set 
                    {  
                        tableName = value;  
                    }  
                }  
                public string ColumnName  
                {  
                    get 
                    {  
                        return columnName;  
                    }  
                    set 
                    {  
                        columnName = value;  
                    }  
                }  
                public int? ReportTableHeirarchyId  
                {  
                    get 
                    {  
                        return reportTableHeirarchyID;  
                    }  
                    set 
                    {  
                        reportTableHeirarchyID = value;  
                    }  
                }  
                public string Heading  
                {  
                    get 
                    {  
                        return heading;  
                    }  
                    set 
                    {  
                        heading = value;  
                    }  
                }  
                public string Description  
                {  
                    get 
                    {  
                        return description;  
                    }  
                    set 
                    {  
                        description = value;  
                    }  
                }  
                public bool Filterable  
                {  
                    get 
                    {  
                        return filterable;  
                    }  
                    set 
                    {  
                        filterable = value;  
                    }  
                }  
                public int ReportColumnTypeID  
                {  
                    get 
                    {  
                        return reportColumnTypeID;  
                    }  
                    set 
                    {  
                        reportColumnTypeID = value;  
                    }  
                }  
                public string ColumnType  
                {  
                    get 
                    {  
                        return columnType;  
                    }  
                    set 
                    {  
                        columnType = value;  
                    }  
                }  
                public string DataFormatString  
                {  
                    get 
                    {  
                        return dataFormatString;  
                    }  
                    set 
                    {  
                        dataFormatString = value;  
                    }  
                }  
                public string DataType  
                {  
                    get 
                    {  
                        return dataType;  
                    }  
                    set 
                    {  
                        dataType = value;  
                    }  
                }  
                public string EmptyDataText  
                {  
                    get 
                    {  
                        return emptyDataText;  
                    }  
                    set 
                    {  
                        emptyDataText = value;  
                    }  
                }  
                public bool AllowFiltering  
                {  
                    get 
                    {  
                        return allowFiltering;  
                    }  
                    set 
                    {  
                        allowFiltering = value;  
                    }  
                }  
                public bool AllowSorting  
                {  
                    get 
                    {  
                        return allowSorting;  
                    }  
                    set 
                    {  
                        allowSorting = value;  
                    }  
                }  
                public bool ShowFilterIcon  
                {  
                    get 
                    {  
                        return showFilterIcon;  
                    }  
                    set 
                    {  
                        showFilterIcon = value;  
                    }  
                }  
                public bool ShowSortIcon  
                {  
                    get 
                    {  
                        return showSortIcon;  
                    }  
                    set 
                    {  
                        showSortIcon = value;  
                    }  
                }  
                public string HeaderStyleWidth  
                {  
                    get 
                    {  
                        return headerStyleWidth;  
                    }  
                    set 
                    {  
                        headerStyleWidth = value;  
                    }  
                }  
                public string Aggregate  
                {  
                    get 
                    {  
                        return aggregate;  
                    }  
                    set 
                    {  
                        aggregate = value;  
                    }  
                }  
                public string SortExpression  
                {  
                    get 
                    {  
                        return sortExpression;  
                    }  
                    set 
                    {  
                        sortExpression = value;  
                    }  
                }  
                public string DataField  
                {  
                    get 
                    {  
                        return dataField;  
                    }  
                    set 
                    {  
                        dataField = value;  
                    }  
                }  
                public string FooterAggregateFormatString  
                {  
                    get 
                    {  
                        return footerAggregateFormatString;  
                    }  
                    set 
                    {  
                        footerAggregateFormatString = value;  
                    }  
                }  
                public bool ActiveColumn  
                {  
                    get 
                    {  
                        return activeColumn;  
                    }  
                    set 
                    {  
                        activeColumn = value;  
                    }  
                }  
                public bool Removed  
                {  
                    get 
                    {  
                        return removed;  
                    }  
                    set 
                    {  
                        removed = value;  
                    }  
                }  
                public DateTime? PurgeDate  
                {  
                    get 
                    {  
                        return purgeDate;  
                    }  
                    set 
                    {  
                        purgeDate = value;  
                    }  
                }  
                public int UserCreatedId  
                {  
                    get 
                    {  
                        return userCreatedID;  
                    }  
                    set 
                    {  
                        userCreatedID = value;  
                    }  
                }  
                public int UserModifiedId  
                {  
                    get 
                    {  
                        return userModifiedID;  
                    }  
                    set 
                    {  
                        userModifiedID = value;  
                    }  
                }  
                public DateTime created  
                {  
                    get 
                    {  
                        return Created;  
                    }  
                    set 
                    {  
                        Created = value;  
                    }  
                }  
                public DateTime modified  
                {  
                    get 
                    {  
                        return Modified;  
                    }  
                    set 
                    {  
                        Modified = value;  
                    }  
                }  
            }
            #endregion  
 
            #region Filter Info Class  
 
            //Class to hold the data of filter data for report  
            public class filterInfo  
            {  
                int ID;  
                string colName;  
                string colDataType;  
                string colValue;  
                string tableName;  
                int? reportTableHeirarchyID;  
 
                public filterInfo(int Id, string cName, string cDataType, string cValue, string tName, int? treportTableHeirarchyID)  
                {  
                    ID = Id;  
                    colName = cName;  
                    colValue = cValue;  
                    tableName = tName;  
                    colDataType = cDataType;  
                    reportTableHeirarchyID = treportTableHeirarchyID;  
                }  
                public int Id  
                {  
                    get 
                    {  
                        return ID;  
                    }  
                    set 
                    {  
                        ID = value;  
                    }  
                }  
                public string ColName  
                {  
                    get 
                    {  
                        return colName;  
                    }  
                    set 
                    {  
                        colName = value;  
                    }  
                }  
                public string ColDataType  
                {  
                    get 
                    {  
                        return colDataType;  
                    }  
                    set 
                    {  
                        colDataType = value;  
                    }  
                }  
                public string ColValue  
                {  
                    get 
                    {  
                        return colValue;  
                    }  
                    set 
                    {  
                        colValue = value;  
                    }  
                }  
                public string TableName  
                {  
                    get 
                    {  
                        return tableName;  
                    }  
                    set 
                    {  
                        tableName = value;  
                    }  
                }  
                public int? ReportTableHeirarchyId  
                {  
                    get 
                    {  
                        return reportTableHeirarchyID;  
                    }  
                    set 
                    {  
                        reportTableHeirarchyID = value;  
                    }  
                }  
            }
            #endregion  
 
        #endregion
        #region Page Load  
 
            //Function Page Load  
            protected void Page_Load(object sender, EventArgs e)  
            {  
                if (!IsPostBack && !IsCallback)  
                {  
                    createReportMenu();  
                    if (((from data in dbcontext.userDetails where data.userID == SessionWrapper.userID && data.role.customer.waivestarCustomer == true select data).Count() > 0) == true)  
                    {  
                        foreach (RadMenuItem item in reportRadMenu.Items)  
                        {  
                            (item.Items.FindItemByText("New Report")).Visible = true;  
                            (item.Items.FindItemByText("Edit Report")).Visible = true;  
                        }  
                    }  
                    else 
                    {  
                        foreach (RadMenuItem item in reportRadMenu.Items)  
                        {  
                            (item.Items.FindItemByText("New Report")).Visible = false;  
                            (item.Items.FindItemByText("Edit Report")).Visible = true;  
                        }  
                    }  
 
                    switch (Request.QueryString["type"])  
                    {  
                        case "Insert": newReport();  
                            break;  
 
                        case "Edit": editReport();  
                            break;  
 
                        case "ReadOnly": viewReport();  
                            break;  
                    }  
                }              
            }  
 
            //Function to create the reports RadMenu  
            protected void createReportMenu()  
            {  
                //determine which reports the user can see              
                businessLevel bl = (from b in dbcontext.businessLevels where b.businessLevelID == SessionWrapper.businessLevelID select b).FirstOrDefault();  
                int[] arr = new int[(int)bl.lvl];  
                arr[(int)bl.lvl - 1] = (int)bl.businessLevelID;  
                int? currentParent = bl.parentID;  
                while (currentParent != null)  
                {  
                    businessLevel parent = (from b in dbcontext.businessLevels where b.businessLevelID == currentParent select b).FirstOrDefault();  
                    arr[(int)parent.lvl - 1] = (int)currentParent;  
                    currentParent = parent.parentID;  
                }  
 
                var reps = (from r in dbcontext.reports  
                            join rrv in dbcontext.reportRoleVisibilities on r.reportID equals rrv.reportID into v  
                            from rrv in v.DefaultIfEmpty()  
                            join rbl in dbcontext.reportBusinessLevelVisibilities on r.reportID equals rbl.reportID into b  
                            from rbl in b.DefaultIfEmpty()  
                            where rrv.roleID == SessionWrapper.roleID ||  
                            arr.Contains(rbl.businessLevelID) ||  
                            r.customerID == SessionWrapper.customerID  
                            select r).Distinct();  
 
                reportRadMenu.DataSource = reps;  
                reportRadMenu.DataBind();  
 
                foreach (RadMenuItem menuItem in reportRadMenu.Items)  
                {  
                    //Creating Child Item  
                    RadMenuItem newItem = new RadMenuItem("New Report");  
                    newItem.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(RadTreeView), "Telerik.Web.UI.Skins." + SessionWrapper.skin + ".Grid.AddRecord.gif");  
                    menuItem.Items.Add(newItem);  
                    RadMenuItem editItem = new RadMenuItem("Edit Report");  
                    editItem.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(RadTreeView), "Telerik.Web.UI.Skins." + SessionWrapper.skin + ".Grid.Update.gif");  
                    menuItem.Items.Add(editItem);  
                }  
            }
        #endregion  
 
        #region Report Menu Selection  
 
            //Event Handler - OnItemClick for the Report RadMenu  
            protected void reportRadMenuItemClick(object sender, RadMenuEventArgs e)  
            {  
                switch (e.Item.Text)  
                {  
                    case "New Report":Response.Redirect("~/reportGenerateReport.aspx?type=Insert&reportID=" + 0);  
                        break;  
 
                    case "Edit Report": RadMenuItem selectedItem = (RadMenuItem)e.Item.Parent;  
                        selectedItem.Selected = true;  
                        Response.Redirect("~/reportGenerateReport.aspx?type=Edit&reportID=" + selectedItem.Value);                          
                        break;  
 
                    default: Response.Redirect("~/reportGenerateReport.aspx?type=ReadOnly&reportID=" + e.Item.Value);   
                        break;               
                }  
            }
        #endregion  
 
        #region Filter/View Report  
 
            //Function to view the report  
            protected void viewReport()  
            {  
                reportFormView.DefaultMode = FormViewMode.ReadOnly;  
                reportFormView.ChangeMode(FormViewMode.ReadOnly);  
                //Retrieving the reports data  
                var report = from repData in dbcontext.reports  
                             where repData.reportID == int.Parse(Request.QueryString["reportID"])  
                             select repData;  
 
                if (report.Count() != 0)  
                {  
                    reportFormView.DataSource = report;  
                    reportFormView.DataBind();  
 
                    RadGrid grid = (RadGrid)reportFormView.FindControl("reportGrid");  
                    RadAjaxPanel1.Visible = false;  
                    //Checking filterable columns for the report                  
                    var filter = from filterData in dbcontext.reportColumns  
                                 where filterData.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                       filterData.filterable == true 
                                 select new 
                                 {  
                                     filterData.dataType,  
                                     filterData.columnName,  
                                     filterData.reportID,  
                                     reportTableListID = filterData.report.reportTableListID,  
                                     filterData.reportTableHeirarchyID  
                                 };  
 
                    //Displaying filters for the report if applicable else present thme with the report data  
                    if (filter.Count() != 0)  
                    {  
                        //Retrieving the filters data  
                        var filters = (from filterData in filter.AsEnumerable()  
                                       select new 
                                       {  
                                           filterData.dataType,  
                                           filterData.reportID,  
                                           filterData.reportTableHeirarchyID,  
                                           columnName = (string.IsNullOrEmpty(filterData.reportTableHeirarchyID.ToString()) ? filterData.columnName : filterData.reportTableHeirarchyID.ToString()),  
                                           tableName = (string.IsNullOrEmpty(filterData.reportTableHeirarchyID.ToString()) ? (from data in dbcontext.reportTableLists where data.reportTableListID == filterData.reportTableListID select data.name).First() :  
                                                                                                                             (from data in dbcontext.reportTableHeirarchyLists where data.reportTableHeirarchyListID == (from dat in dbcontext.reportTableHeirarchies where dat.reportTableHeirarchyID == filterData.reportTableHeirarchyID select dat.reportTableHeirarchyListID).First() select data.name).First()),  
                                           labelText = (string.IsNullOrEmpty(filterData.reportTableHeirarchyID.ToString()) ? (from data in dbcontext.reportTableLists where data.reportTableListID == filterData.reportTableListID select data.name).First() + "-" + filterData.columnName :  
                                                                                                                             (from data in dbcontext.reportTableHeirarchyLists where data.reportTableHeirarchyListID == (from dat in dbcontext.reportTableHeirarchies where dat.reportTableHeirarchyID == filterData.reportTableHeirarchyID select dat.reportTableHeirarchyListID).First() select data.name).First() + "-" + filterData.columnName)  
                                       }).ToList();  
 
                        //databinding the filters Repeater  
                        ((System.Web.UI.WebControls.Panel)reportFormView.FindControl("reportPanel")).Visible = false;  
                        ((System.Web.UI.WebControls.Panel)reportFormView.FindControl("filterPanel")).Visible = true;  
                        ((Repeater)reportFormView.FindControl("filterRepeater")).DataSource = filters;  
                        ((Repeater)reportFormView.FindControl("filterRepeater")).DataBind();  
                        //createReport();  
                    }  
                    else 
                    {  
                        ((System.Web.UI.WebControls.Panel)reportFormView.FindControl("reportPanel")).Visible = true;  
                        ((System.Web.UI.WebControls.Panel)reportFormView.FindControl("filterPanel")).Visible = false;  
                        createReport();  
                    }  
                    //RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(grid, grid);  
                }  
            }  
 
            //Function called when 'Filter' button is clicked to confirm the filtering of the report data  
            protected void btFilterClick(object sender, EventArgs e)  
            {  
                Button bt = (Button)sender;  
                int count = 0;  
                Session["filterList"] = null;  
 
                foreach (RepeaterItem item in ((Repeater)reportFormView.FindControl("filterRepeater")).Items)  
                {  
                    if (Session["filterList"] != null)  
                    {  
                        if (item.FindControl("textboxPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadTextBox)item.FindControl("rtbFilterTextBox")).Text))  
                            {  
                                ArrayList filterList = (ArrayList)Session["filterList"];  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["column"], "string", ((RadTextBox)item.FindControl("rtbFilterTextBox")).Text, ((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("numericTextBoxPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadNumericTextBox)item.FindControl("rtbFilterNumericTextBox")).Text))  
                            {  
                                ArrayList filterList = (ArrayList)Session["filterList"];  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["column"], "number", ((RadNumericTextBox)item.FindControl("rtbFilterNumericTextBox")).Text, ((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("decimalTextBoxPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadNumericTextBox)item.FindControl("rtbFilterDecimalTextBox")).Text))  
                            {  
                                ArrayList filterList = (ArrayList)Session["filterList"];  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["column"], "decimal", ((RadNumericTextBox)item.FindControl("rtbFilterDecimalTextBox")).Text, ((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("datePickerPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadDatePicker)item.FindControl("rdpFilterFrom")).SelectedDate.ToString()))  
                            {  
                                ArrayList filterList = (ArrayList)Session["filterList"];  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["column"] + "From""date", ((RadDatePicker)item.FindControl("rdpFilterFrom")).SelectedDate.ToString(), ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                            if (!string.IsNullOrEmpty(((RadDatePicker)item.FindControl("rdpFilterTo")).SelectedDate.ToString()))  
                            {  
                                ArrayList filterList = (ArrayList)Session["filterList"];  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["column"] + "To""date", ((RadDatePicker)item.FindControl("rdpFilterFrom")).SelectedDate.ToString(), ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("booleanCheckBoxPanel").Visible == true)  
                        {  
                            if (((CheckBox)item.FindControl("cbFilterCheckBox")).Checked)  
                            {  
                                ArrayList filterList = (ArrayList)Session["filterList"];  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["column"], "bool", ((CheckBox)item.FindControl("cbFilterCheckBox")).Checked.ToString(), ((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                    }  
                    else 
                    {  
                        if (item.FindControl("textboxPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadTextBox)item.FindControl("rtbFilterTextBox")).Text))  
                            {  
                                ArrayList filterList = new ArrayList();  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["column"], "string", ((RadTextBox)item.FindControl("rtbFilterTextBox")).Text, ((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbTextBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("numericTextBoxPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadNumericTextBox)item.FindControl("rtbFilterNumericTextBox")).Text))  
                            {  
                                ArrayList filterList = new ArrayList();  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["column"], "number", ((RadNumericTextBox)item.FindControl("rtbFilterNumericTextBox")).Text, ((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbNTextBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("decimalTextBoxPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadNumericTextBox)item.FindControl("rtbFilterDecimalTextBox")).Text))  
                            {  
                                ArrayList filterList = new ArrayList();  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["column"], "decimal", ((RadNumericTextBox)item.FindControl("rtbFilterDecimalTextBox")).Text, ((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbDTextBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("datePickerPanel").Visible == true)  
                        {  
                            if (!string.IsNullOrEmpty(((RadDatePicker)item.FindControl("rdpFilterFrom")).SelectedDate.ToString()))  
                            {  
                                ArrayList filterList = new ArrayList();  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["column"] + "From""date", ((RadDatePicker)item.FindControl("rdpFilterFrom")).SelectedDate.ToString(), ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                            if (!string.IsNullOrEmpty(((RadDatePicker)item.FindControl("rdpFilterTo")).SelectedDate.ToString()))  
                            {  
                                ArrayList filterList = new ArrayList();  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["column"] + "To""date", ((RadDatePicker)item.FindControl("rdpFilterFrom")).SelectedDate.ToString(), ((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbDateFromLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                        if (item.FindControl("booleanCheckBoxPanel").Visible == true)  
                        {  
                            if (((CheckBox)item.FindControl("cbFilterCheckBox")).Checked)  
                            {  
                                ArrayList filterList = new ArrayList();  
                                filterList.Add(new filterInfo(count, ((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["column"], "bool", ((CheckBox)item.FindControl("cbFilterCheckBox")).Checked.ToString(), ((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["table"], (!string.IsNullOrEmpty(((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["hierarchyID"]) ? (int?)int.Parse(((System.Web.UI.WebControls.Label)item.FindControl("lbCheckBoxLabel1")).Attributes["hierarchyID"]) : (int?)null)));  
                                Session["filterList"] = filterList;  
                                count++;  
                            }  
                        }  
                    }  
                }  
                ((System.Web.UI.WebControls.Panel)reportFormView.FindControl("reportPanel")).Visible = true;  
                ((System.Web.UI.WebControls.Panel)reportFormView.FindControl("filterPanel")).Visible = false;  
                createReport();  
                ((RadGrid)reportFormView.FindControl("reportGrid")).Rebind();  
            }  
 
            //Function called when 'Cancel' button is clicked to cancel the filtering of the report data  
            protected void btCancelFilterClick(object sender, EventArgs e)  
            {  
                createReport();  
            }  
 
            //Function to check whether the ReportColumns are filterable or not  
            protected void createReport()  
            {  
                //Retrieving the reports data  
                var report = from repData in dbcontext.reports  
                             where repData.reportID == int.Parse(Request.QueryString["reportID"])  
                             select repData;  
 
                if (report.Count() != 0)  
                {                      
                    RadGrid reportGrid = ((RadGrid)reportFormView.FindControl("reportGrid"));                      
                    reportGrid.MasterTableView.Columns.Clear();  
                    reportGrid.PageSize = report.First().pageSize;  
                    reportGrid.MasterTableView.PageSize = report.First().pageSize;  
                    reportGrid.MasterTableView.AutoGenerateColumns = false;  
                    reportGrid.MasterTableView.DataKeyNames = dbcontext.GetPrimaryKeyByTable(report.First().reportTableList.name);  
                    if (report.First().hierarchical != true)  
                    {  
                        //Creating and Adding columns for the MasterTableView   
                        reportGridMasterTableViewColumns(reportGrid);  
                    }  
                    else 
                    {  
                        if (report.First().hierarchical == true)  
                        {  
                            //Retrieving data for the hierarchies to be added to the MasterTableView   
                            //i.e at Second Level Hierarchy - the hierarhcies with parent id as 'Null'  
                            var hierarchies = from hierData in dbcontext.reportTableHeirarchies  
                                              where hierData.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                              hierData.parentID == null && hierData.active == true &&  
                                              hierData.removed == false 
                                              select hierData;  
 
                            if (hierarchies.Count() != 0)  
                            {  
                                //Creating the DetailTable to MasterTableView  
                                createMasterViewDetailTable(reportGrid, hierarchies);  
                                //Creating and Adding columns for the MasterTableView   
                                reportGridMasterTableViewColumns(reportGrid);  
                            }  
                        }  
                    }                      
                }  
            }  
 
            //Function to create dynamic columns for the MasterTableView of report RadGrid  
            protected void reportGridMasterTableViewColumns(RadGrid reportGrid)  
            {  
                var reportColumns = from data in dbcontext.reportColumns  
                                    where data.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                          data.reportTableHeirarchyID == null &&  
                                          data.active == true && data.removed == false 
                                    select data;  
 
                if (reportColumns.Count() != 0)  
                {                    
                    bool duplicatePKColumn = false;  
                    //Checking if primary key column is included in report columns or not  
                    foreach (var data in reportColumns)  
                    {  
                        if (data.columnName == reportGrid.MasterTableView.DataKeyNames[0])  
                        {  
                            duplicatePKColumn = true;  
                            break;  
                        }  
                    }  
                    if (duplicatePKColumn == false)  
                    {  
                        //Adding a default primary key column to the collection  
                        GridBoundColumn gridDefaultColumn = new GridBoundColumn();  
                        //Add primary key column to the collection  
                        reportGrid.MasterTableView.Columns.Add(gridDefaultColumn);  
                        //Then set properties                                                                                                         
                        gridDefaultColumn.DataField = reportGrid.MasterTableView.DataKeyNames[0];  
                        gridDefaultColumn.UniqueName = reportGrid.MasterTableView.DataKeyNames[0];  
                        gridDefaultColumn.Visible = false;  
                    }  
                    foreach (var data in reportColumns)  
                    {  
                        switch (data.reportColumnType.name)  
                        {  
                            case "GridBoundColumn":  
 
                                GridBoundColumn gridBColumn = new GridBoundColumn();  
                                //Add column to the collection  
                                reportGrid.MasterTableView.Columns.Add(gridBColumn);  
 
                                //Then set properties                                                                                 
                                gridBColumn.Aggregate = GridAggregateFunction.None;  
                                gridBColumn.AllowFiltering = data.allowFiltering;  
                                gridBColumn.AllowSorting = data.allowSorting;  
                                gridBColumn.DataField = data.columnName;  
                                gridBColumn.DataFormatString = data.dataFormatString;  
                                gridBColumn.DataType = Type.GetType(data.dataType);  
                                gridBColumn.EmptyDataText = data.emptyDataText;  
                                gridBColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                gridBColumn.HeaderText = data.heading;  
                                gridBColumn.HeaderTooltip = data.description;  
                                gridBColumn.ShowFilterIcon = data.showFilterIcon;  
                                gridBColumn.ShowSortIcon = data.showSortIcon;  
                                gridBColumn.SortExpression = data.sortExpression;  
                                gridBColumn.UniqueName = data.columnName;  
                                gridBColumn.Visible = data.active;  
 
                                break;  
                            case "GridCheckBoxColumn":  
 
                                GridCheckBoxColumn gridCBColumn = new GridCheckBoxColumn();  
                                //Add column to the collection  
                                reportGrid.MasterTableView.Columns.Add(gridCBColumn);  
 
                                //Then set properties                                                                                 
                                gridCBColumn.AllowFiltering = data.allowFiltering;  
                                gridCBColumn.AllowSorting = data.allowSorting;  
                                gridCBColumn.DataField = data.dataField;  
                                gridCBColumn.DataType = Type.GetType(data.dataType);  
                                gridCBColumn.HeaderText = data.heading;  
                                gridCBColumn.HeaderTooltip = data.description;  
                                gridCBColumn.ShowFilterIcon = data.showFilterIcon;  
                                gridCBColumn.ShowSortIcon = data.showSortIcon;  
                                gridCBColumn.SortExpression = data.sortExpression;  
                                gridCBColumn.UniqueName = data.columnName;  
                                gridCBColumn.Visible = data.active;  
 
                                break;  
                            case " GridBinaryImageColumn":  
                                GridBinaryImageColumn gridBIColumn = new GridBinaryImageColumn();  
                                //Add column to the collection  
                                reportGrid.MasterTableView.Columns.Add(gridBIColumn);  
 
                                //Then set properties        
                                gridBIColumn.AlternateText = data.heading;  
                                gridBIColumn.AllowFiltering = data.allowFiltering;  
                                gridBIColumn.AllowSorting = data.allowSorting;  
                                gridBIColumn.DataField = data.dataField;  
                                gridBIColumn.DataType = Type.GetType(data.dataType);  
                                gridBIColumn.HeaderText = data.heading;  
                                gridBIColumn.HeaderTooltip = data.description;  
                                gridBIColumn.ShowFilterIcon = data.showFilterIcon;  
                                gridBIColumn.ShowSortIcon = data.showSortIcon;  
                                gridBIColumn.SortExpression = data.sortExpression;  
                                gridBIColumn.UniqueName = data.columnName;  
                                gridBIColumn.Visible = data.active;  
 
                                break;  
                            case "GridCalculatedColumn":  
                                GridCalculatedColumn gridCColumn = new GridCalculatedColumn();  
                                //Add column to the collection  
                                reportGrid.MasterTableView.Columns.Add(gridCColumn);  
 
                                //Then set properties                                                                                 
                                gridCColumn.Aggregate = GridAggregateFunction.None;  
                                gridCColumn.AllowFiltering = data.allowFiltering;  
                                gridCColumn.AllowSorting = data.allowSorting;  
                                gridCColumn.DataType = Type.GetType(data.dataType);  
                                gridCColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                gridCColumn.HeaderText = data.heading;  
                                gridCColumn.HeaderTooltip = data.description;  
                                gridCColumn.ShowFilterIcon = data.showFilterIcon;  
                                gridCColumn.ShowSortIcon = data.showSortIcon;  
                                gridCColumn.SortExpression = data.sortExpression;  
                                gridCColumn.UniqueName = data.columnName;  
                                gridCColumn.Visible = data.active;  
 
                                break;  
                            case "GridDateTimeColumn":  
                                GridDateTimeColumn gridDTColumn = new GridDateTimeColumn();  
                                //Add column to the collection  
                                reportGrid.MasterTableView.Columns.Add(gridDTColumn);  
 
                                //Then set properties                                                                                 
                                gridDTColumn.Aggregate = GridAggregateFunction.None;  
                                gridDTColumn.AllowFiltering = data.allowFiltering;  
                                gridDTColumn.AllowSorting = data.allowSorting;  
                                gridDTColumn.DataField = data.dataField;  
                                gridDTColumn.DataFormatString = data.dataFormatString;  
                                gridDTColumn.DataType = Type.GetType(data.dataType);  
                                gridDTColumn.EmptyDataText = data.emptyDataText;  
                                gridDTColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                gridDTColumn.HeaderText = data.heading;  
                                gridDTColumn.HeaderTooltip = data.description;  
                                gridDTColumn.ShowFilterIcon = data.showFilterIcon;  
                                gridDTColumn.ShowSortIcon = data.showSortIcon;  
                                gridDTColumn.SortExpression = data.sortExpression;  
                                gridDTColumn.UniqueName = data.columnName;  
                                gridDTColumn.Visible = data.active;  
 
                                break;  
                            case "GridNumericColumn":  
                                GridNumericColumn gridNColumn = new GridNumericColumn();  
                                //Add column to the collection  
                                reportGrid.MasterTableView.Columns.Add(gridNColumn);  
 
                                //Then set properties                                                                                 
                                gridNColumn.Aggregate = GridAggregateFunction.None;  
                                gridNColumn.AllowFiltering = data.allowFiltering;  
                                gridNColumn.AllowSorting = data.allowSorting;  
                                gridNColumn.DataField = data.dataField;  
                                gridNColumn.DataFormatString = data.dataFormatString;  
                                gridNColumn.DataType = Type.GetType(data.dataType);  
                                if (data.dataType == "Percentage")  
                                {  
                                    gridNColumn.NumericType = NumericType.Percent;  
                                }  
                                else if (data.dataType == "Currency")  
                                {  
                                    gridNColumn.NumericType = NumericType.Currency;  
                                }  
                                else 
                                {  
                                    gridNColumn.NumericType = NumericType.Number;  
                                }  
                                gridNColumn.EmptyDataText = data.emptyDataText;  
                                gridNColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                gridNColumn.HeaderText = data.heading;  
                                gridNColumn.HeaderTooltip = data.description;  
                                gridNColumn.ShowFilterIcon = data.showFilterIcon;  
                                gridNColumn.ShowSortIcon = data.showSortIcon;  
                                gridNColumn.SortExpression = data.sortExpression;  
                                gridNColumn.UniqueName = data.columnName;  
                                gridNColumn.Visible = data.active;  
 
                                break;  
                        }                          
                    }                     
                }  
            }  
 
            //Function to create and add columns of the DetailTable-Second in hierarchy level  
            //i.e. Detail Table added to the MasterTableView of the RadGrid  
            protected void createMasterViewDetailTable(RadGrid reportGrid, IQueryable<reportTableHeirarchy> hierarchies)  
            {  
                foreach (var tempData in hierarchies)  
                {  
                    var hierTableName = (from tableData in dbcontext.reportTableHeirarchies  
                                         where tableData.reportID == tempData.reportID &&  
                                               tableData.reportTableHeirarchyID == tempData.reportTableHeirarchyID  
                                         select new { name = tableData.reportTableHeirarchyList.name }).First();  
 
                    //Adding Detail table to MasterTableView - Second in hierarchy level  
                    GridTableView hierTableView = new GridTableView(reportGrid);  
                    reportGrid.MasterTableView.DetailTables.Add(hierTableView);  
 
                    //Then Set Properties for the Detail Table  
                    hierTableView.DataKeyNames = dbcontext.GetPrimaryKeyByTable(hierTableName.name);  
                    hierTableView.DataMember = tempData.reportTableHeirarchyID.ToString();  
                    //hierTableView.HierarchyDefaultExpanded = true;  
                    hierTableView.AllowPaging = true;  
                    hierTableView.AllowSorting = true;  
                    hierTableView.AllowFilteringByColumn = true;  
                    hierTableView.AutoGenerateColumns = false;  
 
                    GridRelationFields relationFields = new GridRelationFields();  
                    relationFields.MasterKeyField = reportGrid.MasterTableView.DataKeyNames[0];  
                    relationFields.DetailKeyField = reportGrid.MasterTableView.DataKeyNames[0];  
                    hierTableView.ParentTableRelation.Add(relationFields);  
 
                    //Creating and Adding the DetailTable to MasterTableView  
                    createChildDetailTables(tempData, hierTableView);  
 
                    var hierReportColumns = from data in dbcontext.reportColumns  
                                            where data.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                                 data.reportTableHeirarchyID == tempData.reportTableHeirarchyID &&  
                                                 data.active == true && data.removed == false 
                                            select data;  
 
                    if (hierReportColumns.Count() != 0)  
                    {  
                        bool duplicatePKColumn = false;  
                        //Checking if primary key column is included in report columns or not  
                        foreach (var data in hierReportColumns)  
                        {  
                            if (data.columnName == hierTableView.DataKeyNames[0])  
                            {  
                                duplicatePKColumn = true;  
                                break;  
                            }  
                        }  
                        if (duplicatePKColumn == false)  
                        {  
                            //Adding a default primary key column to the collection  
                            GridBoundColumn gridDefaultColumn = new GridBoundColumn();  
                            //Add primary key column to the collection  
                            hierTableView.Columns.Add(gridDefaultColumn);  
 
                            //Then set properties                                                                                                         
                            gridDefaultColumn.DataField = hierTableView.DataKeyNames[0];  
                            gridDefaultColumn.UniqueName = hierTableView.DataKeyNames[0];  
                            gridDefaultColumn.Visible = false;  
                        }  
 
                        foreach (var data in hierReportColumns)  
                        {  
                            switch (data.reportColumnType.name)  
                            {  
                                case "GridBoundColumn":  
 
                                    GridBoundColumn gridBColumn = new GridBoundColumn();  
                                    //Add column to the collection  
                                    hierTableView.Columns.Add(gridBColumn);  
 
                                    //Then set properties                                                                                 
                                    gridBColumn.Aggregate = GridAggregateFunction.None;  
                                    gridBColumn.AllowFiltering = data.allowFiltering;  
                                    gridBColumn.AllowSorting = data.allowSorting;  
                                    gridBColumn.DataField = data.columnName;  
                                    gridBColumn.DataFormatString = data.dataFormatString;  
                                    gridBColumn.DataType = Type.GetType(data.dataType);  
                                    gridBColumn.EmptyDataText = data.emptyDataText;  
                                    gridBColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                    gridBColumn.HeaderText = data.heading;  
                                    gridBColumn.HeaderTooltip = data.description;  
                                    gridBColumn.ShowFilterIcon = data.showFilterIcon;  
                                    gridBColumn.ShowSortIcon = data.showSortIcon;  
                                    gridBColumn.SortExpression = data.sortExpression;  
                                    gridBColumn.UniqueName = data.columnName;  
                                    gridBColumn.Visible = data.active;  
 
                                    break;  
                                case "GridCheckBoxColumn":  
 
                                    GridCheckBoxColumn gridCBColumn = new GridCheckBoxColumn();  
                                    //Add column to the collection  
                                    hierTableView.Columns.Add(gridCBColumn);  
 
                                    //Then set properties                                                                                 
                                    gridCBColumn.AllowFiltering = data.allowFiltering;  
                                    gridCBColumn.AllowSorting = data.allowSorting;  
                                    gridCBColumn.DataField = data.dataField;  
                                    gridCBColumn.DataType = Type.GetType(data.dataType);  
                                    gridCBColumn.HeaderText = data.heading;  
                                    gridCBColumn.HeaderTooltip = data.description;  
                                    gridCBColumn.ShowFilterIcon = data.showFilterIcon;  
                                    gridCBColumn.ShowSortIcon = data.showSortIcon;  
                                    gridCBColumn.SortExpression = data.sortExpression;  
                                    gridCBColumn.UniqueName = data.columnName;  
                                    gridCBColumn.Visible = data.active;  
 
                                    break;  
                                case " GridBinaryImageColumn":  
                                    GridBinaryImageColumn gridBIColumn = new GridBinaryImageColumn();  
                                    //Add column to the collection  
                                    hierTableView.Columns.Add(gridBIColumn);  
 
                                    //Then set properties        
                                    gridBIColumn.AlternateText = data.heading;  
                                    gridBIColumn.AllowFiltering = data.allowFiltering;  
                                    gridBIColumn.AllowSorting = data.allowSorting;  
                                    gridBIColumn.DataField = data.dataField;  
                                    gridBIColumn.DataType = Type.GetType(data.dataType);  
                                    gridBIColumn.HeaderText = data.heading;  
                                    gridBIColumn.HeaderTooltip = data.description;  
                                    gridBIColumn.ShowFilterIcon = data.showFilterIcon;  
                                    gridBIColumn.ShowSortIcon = data.showSortIcon;  
                                    gridBIColumn.SortExpression = data.sortExpression;  
                                    gridBIColumn.UniqueName = data.columnName;  
                                    gridBIColumn.Visible = data.active;  
 
                                    break;  
                                case "GridCalculatedColumn":  
                                    GridCalculatedColumn gridCColumn = new GridCalculatedColumn();  
                                    //Add column to the collection  
                                    hierTableView.Columns.Add(gridCColumn);  
 
                                    //Then set properties                                                                                 
                                    gridCColumn.Aggregate = GridAggregateFunction.None;  
                                    gridCColumn.AllowFiltering = data.allowFiltering;  
                                    gridCColumn.AllowSorting = data.allowSorting;  
                                    gridCColumn.DataType = Type.GetType(data.dataType);  
                                    gridCColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                    gridCColumn.HeaderText = data.heading;  
                                    gridCColumn.HeaderTooltip = data.description;  
                                    gridCColumn.ShowFilterIcon = data.showFilterIcon;  
                                    gridCColumn.ShowSortIcon = data.showSortIcon;  
                                    gridCColumn.SortExpression = data.sortExpression;  
                                    gridCColumn.UniqueName = data.columnName;  
                                    gridCColumn.Visible = data.active;  
 
                                    break;  
                                case "GridDateTimeColumn":  
                                    GridDateTimeColumn gridDTColumn = new GridDateTimeColumn();  
                                    //Add column to the collection  
                                    hierTableView.Columns.Add(gridDTColumn);  
 
                                    //Then set properties                                                                                 
                                    gridDTColumn.Aggregate = GridAggregateFunction.None;  
                                    gridDTColumn.AllowFiltering = data.allowFiltering;  
                                    gridDTColumn.AllowSorting = data.allowSorting;  
                                    gridDTColumn.DataField = data.dataField;  
                                    gridDTColumn.DataFormatString = data.dataFormatString;  
                                    gridDTColumn.DataType = Type.GetType(data.dataType);  
                                    gridDTColumn.EmptyDataText = data.emptyDataText;  
                                    gridDTColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                    gridDTColumn.HeaderText = data.heading;  
                                    gridDTColumn.HeaderTooltip = data.description;  
                                    gridDTColumn.ShowFilterIcon = data.showFilterIcon;  
                                    gridDTColumn.ShowSortIcon = data.showSortIcon;  
                                    gridDTColumn.SortExpression = data.sortExpression;  
                                    gridDTColumn.UniqueName = data.columnName;  
                                    gridDTColumn.Visible = data.active;  
 
                                    break;  
                                case "GridNumericColumn":  
                                    GridNumericColumn gridNColumn = new GridNumericColumn();  
                                    //Add column to the collection  
                                    hierTableView.Columns.Add(gridNColumn);  
 
                                    //Then set properties                                                                                 
                                    gridNColumn.Aggregate = GridAggregateFunction.None;  
                                    gridNColumn.AllowFiltering = data.allowFiltering;  
                                    gridNColumn.AllowSorting = data.allowSorting;  
                                    gridNColumn.DataField = data.dataField;  
                                    gridNColumn.DataFormatString = data.dataFormatString;  
                                    gridNColumn.DataType = Type.GetType(data.dataType);  
                                    if (data.dataType == "Percentage")  
                                    {  
                                        gridNColumn.NumericType = NumericType.Percent;  
                                    }  
                                    else if (data.dataType == "Currency")  
                                    {  
                                        gridNColumn.NumericType = NumericType.Currency;  
                                    }  
                                    else 
                                    {  
                                        gridNColumn.NumericType = NumericType.Number;  
                                    }  
                                    gridNColumn.EmptyDataText = data.emptyDataText;  
                                    gridNColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                    gridNColumn.HeaderText = data.heading;  
                                    gridNColumn.HeaderTooltip = data.description;  
                                    gridNColumn.ShowFilterIcon = data.showFilterIcon;  
                                    gridNColumn.ShowSortIcon = data.showSortIcon;  
                                    gridNColumn.SortExpression = data.sortExpression;  
                                    gridNColumn.UniqueName = data.columnName;  
                                    gridNColumn.Visible = data.active;  
 
                                    break;  
                            }  
                        }  
                    }  
                }  
            }  
 
            //Function - Recursive to create and add columns of the DetailTable-Any hierarchy level  
            //i.e. Detail Table added to the other DetailsTables added to the MasterTableView of the RadGrid  
            protected void createChildDetailTables(reportTableHeirarchy tempData, GridTableView hierTableView)  
            {  
                //Retrieving the report Heirarchies for the next levels to the Second Level Hierarchy  
                var childHierarchies = from hierData in dbcontext.reportTableHeirarchies  
                                       where hierData.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                       hierData.active == true && hierData.removed == false &&  
                                       hierData.parentID == tempData.reportTableHeirarchyID  
                                       select hierData;  
 
                if (childHierarchies.Count() != 0)  
                {  
                    foreach (var childHiers in childHierarchies)  
                    {  
                        var hierTableName = (from tableData in dbcontext.reportTableHeirarchies  
                                             where tableData.reportID == tempData.reportID &&  
                                                   tableData.reportTableHeirarchyID == childHiers.reportTableHeirarchyID  
                                             select new { name = tableData.reportTableHeirarchyList.name }).First();  
 
                        //Adding Detail table to MasterTableView - Second in hierarchy level  
                        GridTableView childHierTableView = new GridTableView();  
                        hierTableView.DetailTables.Add(childHierTableView);  
 
                        //Then Set Properties for the Detail Table  
                        childHierTableView.DataKeyNames = dbcontext.GetPrimaryKeyByTable(hierTableName.name);  
                        childHierTableView.DataMember = childHiers.reportTableHeirarchyID.ToString();  
                        //childHierTableView.HierarchyDefaultExpanded = true;  
                        childHierTableView.AllowPaging = true;  
                        childHierTableView.AllowSorting = true;  
                        childHierTableView.AllowFilteringByColumn = true;  
                        childHierTableView.AutoGenerateColumns = false;  
 
                        GridRelationFields relationHierFields = new GridRelationFields();  
                        relationHierFields.MasterKeyField = hierTableView.DataKeyNames[0];  
                        relationHierFields.DetailKeyField = hierTableView.DataKeyNames[0];  
                        childHierTableView.ParentTableRelation.Add(relationHierFields);  
 
 
                        //Creating and Adding the DetailTable to MasterTableView  
                        createChildDetailTables(childHiers, hierTableView);  
 
                        var childHierReportColumns = from data in dbcontext.reportColumns  
                                                     where data.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                                     data.reportTableHeirarchyID == childHiers.reportTableHeirarchyID &&  
                                                     data.active == true && data.removed == false 
                                                     select data;  
 
                        if (childHierReportColumns.Count() != 0)  
                        {  
                            bool duplicatePKColumn = false;  
                            //Checking if primary key column is included in report columns or not  
                            foreach (var data in childHierReportColumns)  
                            {  
                                if (data.columnName == childHierTableView.DataKeyNames[0])  
                                {  
                                    duplicatePKColumn = true;  
                                    break;  
                                }  
                            }  
                            if (duplicatePKColumn == false)  
                            {  
                                //Adding a default primary key column to the collection  
                                GridBoundColumn gridDefaultColumn = new GridBoundColumn();  
                                //Add column to the collection  
                                hierTableView.Columns.Add(gridDefaultColumn);  
 
                                //Then set properties                                                                                                         
                                gridDefaultColumn.DataField = childHierTableView.DataKeyNames[0];  
                                gridDefaultColumn.UniqueName = childHierTableView.DataKeyNames[0];  
                                gridDefaultColumn.Visible = false;  
                            }  
 
                            foreach (var data in childHierReportColumns)  
                            {  
                                switch (data.reportColumnType.name)  
                                {  
                                    case "GridBoundColumn":  
 
                                        GridBoundColumn gridBColumn = new GridBoundColumn();  
                                        //Add column to the collection  
                                        childHierTableView.Columns.Add(gridBColumn);  
 
                                        //Then set properties                                                                                 
                                        gridBColumn.Aggregate = GridAggregateFunction.None;  
                                        gridBColumn.AllowFiltering = data.allowFiltering;  
                                        gridBColumn.AllowSorting = data.allowSorting;  
                                        gridBColumn.DataField = data.columnName;  
                                        gridBColumn.DataFormatString = data.dataFormatString;  
                                        gridBColumn.DataType = Type.GetType(data.dataType);  
                                        gridBColumn.EmptyDataText = data.emptyDataText;  
                                        gridBColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                        gridBColumn.HeaderText = data.heading;  
                                        gridBColumn.HeaderTooltip = data.description;  
                                        gridBColumn.ShowFilterIcon = data.showFilterIcon;  
                                        gridBColumn.ShowSortIcon = data.showSortIcon;  
                                        gridBColumn.SortExpression = data.sortExpression;  
                                        gridBColumn.UniqueName = data.columnName;  
                                        gridBColumn.Visible = data.active;  
 
                                        break;  
                                    case "GridCheckBoxColumn":  
 
                                        GridCheckBoxColumn gridCBColumn = new GridCheckBoxColumn();  
                                        //Add column to the collection  
                                        childHierTableView.Columns.Add(gridCBColumn);  
 
                                        //Then set properties                                                                                 
                                        gridCBColumn.AllowFiltering = data.allowFiltering;  
                                        gridCBColumn.AllowSorting = data.allowSorting;  
                                        gridCBColumn.DataField = data.dataField;  
                                        gridCBColumn.DataType = Type.GetType(data.dataType);  
                                        gridCBColumn.HeaderText = data.heading;  
                                        gridCBColumn.HeaderTooltip = data.description;  
                                        gridCBColumn.ShowFilterIcon = data.showFilterIcon;  
                                        gridCBColumn.ShowSortIcon = data.showSortIcon;  
                                        gridCBColumn.SortExpression = data.sortExpression;  
                                        gridCBColumn.UniqueName = data.columnName;  
                                        gridCBColumn.Visible = data.active;  
 
                                        break;  
                                    case " GridBinaryImageColumn":  
                                        GridBinaryImageColumn gridBIColumn = new GridBinaryImageColumn();  
                                        //Add column to the collection  
                                        childHierTableView.Columns.Add(gridBIColumn);  
 
                                        //Then set properties        
                                        gridBIColumn.AlternateText = data.heading;  
                                        gridBIColumn.AllowFiltering = data.allowFiltering;  
                                        gridBIColumn.AllowSorting = data.allowSorting;  
                                        gridBIColumn.DataField = data.dataField;  
                                        gridBIColumn.DataType = Type.GetType(data.dataType);  
                                        gridBIColumn.HeaderText = data.heading;  
                                        gridBIColumn.HeaderTooltip = data.description;  
                                        gridBIColumn.ShowFilterIcon = data.showFilterIcon;  
                                        gridBIColumn.ShowSortIcon = data.showSortIcon;  
                                        gridBIColumn.SortExpression = data.sortExpression;  
                                        gridBIColumn.UniqueName = data.columnName;  
                                        gridBIColumn.Visible = data.active;  
 
                                        break;  
                                    case "GridCalculatedColumn":  
                                        GridCalculatedColumn gridCColumn = new GridCalculatedColumn();  
                                        //Add column to the collection  
                                        childHierTableView.Columns.Add(gridCColumn);  
 
                                        //Then set properties                                                                                 
                                        gridCColumn.Aggregate = GridAggregateFunction.None;  
                                        gridCColumn.AllowFiltering = data.allowFiltering;  
                                        gridCColumn.AllowSorting = data.allowSorting;  
                                        gridCColumn.DataType = Type.GetType(data.dataType);  
                                        gridCColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                        gridCColumn.HeaderText = data.heading;  
                                        gridCColumn.HeaderTooltip = data.description;  
                                        gridCColumn.ShowFilterIcon = data.showFilterIcon;  
                                        gridCColumn.ShowSortIcon = data.showSortIcon;  
                                        gridCColumn.SortExpression = data.sortExpression;  
                                        gridCColumn.UniqueName = data.columnName;  
                                        gridCColumn.Visible = data.active;  
 
                                        break;  
                                    case "GridDateTimeColumn":  
                                        GridDateTimeColumn gridDTColumn = new GridDateTimeColumn();  
                                        //Add column to the collection  
                                        childHierTableView.Columns.Add(gridDTColumn);  
 
                                        //Then set properties                                                                                 
                                        gridDTColumn.Aggregate = GridAggregateFunction.None;  
                                        gridDTColumn.AllowFiltering = data.allowFiltering;  
                                        gridDTColumn.AllowSorting = data.allowSorting;  
                                        gridDTColumn.DataField = data.dataField;  
                                        gridDTColumn.DataFormatString = data.dataFormatString;  
                                        gridDTColumn.DataType = Type.GetType(data.dataType);  
                                        gridDTColumn.EmptyDataText = data.emptyDataText;  
                                        gridDTColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                        gridDTColumn.HeaderText = data.heading;  
                                        gridDTColumn.HeaderTooltip = data.description;  
                                        gridDTColumn.ShowFilterIcon = data.showFilterIcon;  
                                        gridDTColumn.ShowSortIcon = data.showSortIcon;  
                                        gridDTColumn.SortExpression = data.sortExpression;  
                                        gridDTColumn.UniqueName = data.columnName;  
                                        gridDTColumn.Visible = data.active;  
 
                                        break;  
                                    case "GridNumericColumn":  
                                        GridNumericColumn gridNColumn = new GridNumericColumn();  
                                        //Add column to the collection  
                                        childHierTableView.Columns.Add(gridNColumn);  
 
                                        //Then set properties                                                                                 
                                        gridNColumn.Aggregate = GridAggregateFunction.None;  
                                        gridNColumn.AllowFiltering = data.allowFiltering;  
                                        gridNColumn.AllowSorting = data.allowSorting;  
                                        gridNColumn.DataField = data.dataField;  
                                        gridNColumn.DataFormatString = data.dataFormatString;  
                                        gridNColumn.DataType = Type.GetType(data.dataType);  
                                        if (data.dataType == "Percentage")  
                                        {  
                                            gridNColumn.NumericType = NumericType.Percent;  
                                        }  
                                        else if (data.dataType == "Currency")  
                                        {  
                                            gridNColumn.NumericType = NumericType.Currency;  
                                        }  
                                        else 
                                        {  
                                            gridNColumn.NumericType = NumericType.Number;  
                                        }  
                                        gridNColumn.EmptyDataText = data.emptyDataText;  
                                        gridNColumn.FooterAggregateFormatString = data.footerAggregateFormatString;  
                                        gridNColumn.HeaderText = data.heading;  
                                        gridNColumn.HeaderTooltip = data.description;  
                                        gridNColumn.ShowFilterIcon = data.showFilterIcon;  
                                        gridNColumn.ShowSortIcon = data.showSortIcon;  
                                        gridNColumn.SortExpression = data.sortExpression;  
                                        gridNColumn.UniqueName = data.columnName;  
                                        gridNColumn.Visible = data.active;  
 
                                        break;  
                                }  
                            }  
                        }  
                    }  
                }  
            }  
 
 
            //Event Handler - OnNeedDataSource to bind the report Radgrid  
            protected void bindReportGrid(object sender, GridNeedDataSourceEventArgs e)  
            {  
                RadGrid reportGrid = (RadGrid)sender;  
                //Retrieving data for the report columns  
                var reportColumns = from data in dbcontext.reportColumns  
                                    where data.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                          data.reportTableHeirarchyID == null &&  
                                          data.active == true && data.removed == false 
                                    select data;  
 
                if (reportColumns.Count() != 0)  
                {  
                    string dynamicColumns = string.Empty;  
                    List<string> columnsToDisplay = new List<string>();  
                    StringBuilder columnsSearch = new StringBuilder();  
                    //Getting the report table name  
                    string tableName = reportColumns.First().report.reportTableList.name;  
                    foreach (var data in reportColumns)  
                    {  
                        columnsToDisplay.Add(data.columnName);  
                    }  
                    //Building the Dynamic Column Names for linq query for the report  
                    dynamicColumns = buildDynamicColumnNames(dynamicColumns, columnsToDisplay);  
                    //Building the string of Filter Values for linq query for the report  
                    columnsSearch = buildFilteredValues();  
                    //Building and Databinding the Report RadGrid  
                    Type TEntity = Type.GetType((dbcontext.GetType().Namespace + "." + tableName).ToString());  
                    var results = (dbcontext.GetTableByName(tableName));  
                    if (!string.IsNullOrEmpty(columnsSearch.ToString()) && !string.IsNullOrEmpty(dynamicColumns))  
                    {  
                        //Generating records using dynamic linq  
                        var filteredResults = results.Where(columnsSearch.ToString()).Select(dynamicColumns);  
                        if (filteredResults.Count() != 0)  
                        {  
                            //Generating records using dynamic linq  
                            var finalResults = reportRecords(TEntity, filteredResults);  
                            if (finalResults != null)  
                            {  
                                reportGrid.DataSource = finalResults;  
                            }  
                        }  
                        else 
                        {  
                            reportGrid.DataSource = string.Empty;  
                        }  
                    }  
                    else 
                    {  
                        if (!string.IsNullOrEmpty(dynamicColumns))  
                        {  
                            //Generating records using dynamic linq  
                            var filteredResults = results.Select(dynamicColumns);  
                            int startRowIndex = reportGrid.CurrentPageIndex * reportGrid.PageSize;  
                            int maximumRows = reportGrid.PageSize;                            
                            if (filteredResults.Count() != 0)  
                            {  
                                //Generating records using dynamic linq  
                                var finalResults = reportRecords(TEntity, filteredResults);  
                                if (finalResults != null)  
                                {                                      
                                    reportGrid.DataSource = finalResults;                                    
                                }  
                            }  
                            else 
                            {  
                                reportGrid.DataSource = string.Empty;  
                            }  
                        }  
                        else 
                        {  
                            if (results.Count() != 0)  
                            {  
                                //Generating records using dynamic linq  
                                var finalResults = reportRecords(TEntity, results);  
                                if (finalResults != null)  
                                {  
                                    reportGrid.DataSource = finalResults;  
                                }  
                            }  
                            else 
                            {  
                                reportGrid.DataSource = string.Empty;  
                            }  
                        }  
                    }  
                }  
            }  
              
            //EventHandler - OnDetailTableDataBind for the report RadGrid  
            protected void reportGridDetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)  
            {  
                GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;  
                int hierarchyID = int.Parse(e.DetailTableView.DataMember);  
                int parentDataKeyID = (int)dataItem.GetDataKeyValue(dataItem.OwnerTableView.DataKeyNames[0]);  
                string hierTableName = "";  
 
                var hierReportColumns = from data in dbcontext.reportColumns  
                                        where data.reportID == int.Parse(Request.QueryString["reportID"]) &&  
                                        data.reportTableHeirarchyID == hierarchyID &&  
                                        data.active == true && data.removed == false 
                                        select data;  
 
                if (hierReportColumns.Count() != 0)  
                {  
                    string dynamicHeirColumns = string.Empty;  
                    hierTableName = hierReportColumns.First().reportTableHeirarchy.reportTableHeirarchyList.name;  
                    List<string> hierColumnsToDisplay = new List<string>();  
                    StringBuilder hierColumnsSearch = new StringBuilder();  
                    foreach (var data in hierReportColumns)  
                    {  
                        hierColumnsToDisplay.Add(data.columnName);  
                    }  
                    //Adding the DetailTableView's OwnerTableView DataKeyNames as a column to be retrieved using linq  
                    hierColumnsToDisplay.Add(dataItem.OwnerTableView.DataKeyNames[0].ToString());  
                    //Adding the DetailTableView's DataKeyNames as a column to be retrieved using linq  
                    hierColumnsToDisplay.Add(e.DetailTableView.DataKeyNames[0].ToString());  
                    //Building the Dynamic Column Names for linq query for the report  
                    dynamicHeirColumns = buildDynamicColumnNames(dynamicHeirColumns, hierColumnsToDisplay);  
                    //Building the string of Filter Values for linq query for the report  
                    hierColumnsSearch = buildFilteredValues();  
                    //Building and Databinding the Report RadGrid  
                    Type THeirEntity = Type.GetType((dbcontext.GetType().Namespace + "." + hierTableName).ToString());  
                    var hierResults = (dbcontext.GetTableByName(hierTableName));  
                    if (!string.IsNullOrEmpty(hierColumnsSearch.ToString()) && !string.IsNullOrEmpty(dynamicHeirColumns))  
                    {  
                        //Generating records using dynamic linq  
                        var filteredResults = hierResults.Where(hierColumnsSearch.ToString() + " && " + dataItem.OwnerTableView.DataKeyNames[0] + "=" + parentDataKeyID).Select(dynamicHeirColumns);  
                        if (filteredResults.Count() != 0)  
                        {  
                            //Generating records using dynamic linq  
                            var finalResults = reportRecords(THeirEntity, filteredResults);  
                            if (finalResults != null)  
                            {  
                                e.DetailTableView.DataSource = finalResults;  
                            }  
                        }  
                        else 
                        {  
                            e.DetailTableView.DataSource = string.Empty;  
                        }  
                    }  
                    else 
                    {  
                        if (!string.IsNullOrEmpty(dynamicHeirColumns))  
                        {  
                            //Generating records using dynamic linq  
                            var filteredResults = hierResults.Where(dataItem.OwnerTableView.DataKeyNames[0] + "=" + parentDataKeyID).Select(dynamicHeirColumns);  
                            if (filteredResults.Count() != 0)  
                            {  
                                //Generating records using dynamic linq  
                                var finalResults = reportRecords(THeirEntity, filteredResults);  
                                if (finalResults != null)  
                                {  
                                    e.DetailTableView.DataSource = finalResults;  
                                }  
                            }  
                            else 
                            {  
                                e.DetailTableView.DataSource = string.Empty;  
                            }  
                        }  
                        else 
                        {  
                            if (hierResults.Count() != 0)  
                            {  
                                //Generating records using dynamic linq  
                                var filteredResults = hierResults.Where(dataItem.OwnerTableView.DataKeyNames[0] + "=" + parentDataKeyID);  
                                if (filteredResults.Count() != 0)  
                                {  
                                    //Generating records using dynamic linq  
                                    var finalResults = reportRecords(THeirEntity, filteredResults);  
                                    if (finalResults != null)  
                                    {  
                                        e.DetailTableView.DataSource = finalResults;  
                                    }  
                                }  
                                else 
                                {  
                                    e.DetailTableView.DataSource = string.Empty;  
                                }  
                            }  
                            else 
                            {  
                                e.DetailTableView.DataSource = string.Empty;  
                            }  
                        }  
                    }  
                }  
            }  
 
            //Function to build the string of Filter Values for linq query for the report  
            protected StringBuilder buildFilteredValues()  
            {  
                StringBuilder columnsSearch = new StringBuilder();  
                //Building the Where statement parameters for linq query to be used for filtering of the data of the columns for the report  
                if (Session["filterList"] != null)  
                {  
                    ArrayList filterList = (ArrayList)Session["filterList"];  
                    int count = 0;  
                    foreach (filterInfo listItem in filterList)  
                    {  
                        if (count == 0 && count != (filterList.Count - 1))  
                        {  
                            switch (listItem.ColDataType)  
                            {  
                                case "string": columnsSearch.Append(listItem.ColName + "='" + listItem.ColValue + "' && ");  
                                    break;  
                                case "number": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue + " && ");  
                                    break;  
                                case "decimal": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue + " && ");  
                                    break;  
                                case "date": columnsSearch.Append(listItem.ColName + "='" + listItem.ColValue + "' && ");  
                                    break;  
                                case "bool": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue + " && ");  
                                    break;  
                            }  
                        }  
                        else if (count == (filterList.Count - 1))  
                        {  
                            switch (listItem.ColDataType)  
                            {  
                                case "string": columnsSearch.Append(listItem.ColName + "='" + listItem.ColValue + "'");  
                                    break;  
                                case "number": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue);  
                                    break;  
                                case "decimal": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue);  
                                    break;  
                                case "date": columnsSearch.Append(listItem.ColName + "='" + listItem.ColValue + "'");  
                                    break;  
                                case "bool": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue);  
                                    break;  
                            }  
                        }  
                        else 
                        {  
                            switch (listItem.ColDataType)  
                            {  
                                case "string": columnsSearch.Append(listItem.ColName + "='" + listItem.ColValue + "' && ");  
                                    break;  
                                case "number": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue + " && ");  
                                    break;  
                                case "decimal": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue + " && ");  
                                    break;  
                                case "date": columnsSearch.Append(listItem.ColName + "='" + listItem.ColValue + "' && ");  
                                    break;  
                                case "bool": columnsSearch.Append(listItem.ColName + "=" + listItem.ColValue + " && ");  
                                    break;  
                            }  
                        }  
 
                        count++;  
                    }  
                }  
                return columnsSearch;  
            }  
 
            //Function to build the Dynamic Column Names for linq query for the report  
            protected static string buildDynamicColumnNames(string dynamicColumns, List<string> columnsToDisplay)  
            {  
                //Building the Select statement parameters for linq query to be used for display of the columns for the report  
                for (int i = 0; i < columnsToDisplay.Count; i++)  
                {  
                    string col = columnsToDisplay[i];  
                    if (i == 0)  
                    {  
                        dynamicColumns = "new(" + col;  
                    }  
                    else 
                    {  
                        dynamicColumns += "," + col;  
                    }  
                    if (i == columnsToDisplay.Count - 1)  
                    {  
                        dynamicColumns += ")";  
                    }  
                }  
                return dynamicColumns;  
            }  
 
            //Function to retrieve the records /data to create the requested report by the yser  
            protected static object reportRecords(Type TEntity, IQueryable filteredResults)  
            {  
                //Define Type representing List of objects of T type  
                var genericType = typeof(List<>).MakeGenericType(TEntity);  
 
                //Create an object instance of defined type  
                var finalResults = Activator.CreateInstance(genericType);  
 
                //Get method Add from from the list  
                MethodInfo addMethod = finalResults.GetType().GetMethod("Add");  
 
                //Loop through the calling list  
                foreach (var item in filteredResults)  
                {  
                    //Convert each object of the list into T object by calling extension ToType<T>() and add this object to newly created list  
                    addMethod.Invoke(finalResults, new object[] { item.ToType(TEntity) });  
                }  
                return finalResults;  
            }
        #endregion 


Thanks in advance.
Payal

2 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 21 Apr 2010, 10:48 AM
Hello Payal,

I reviewed the setup, and the code seems correct.
If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with more information on the matter.

All the best,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Payal Mandalia
Top achievements
Rank 1
answered on 10 May 2010, 12:19 AM
Hi Yavor,

Thanks for your reply.
I have worked my way around to this problem and now have my code working the way I wanted it to be .
The only thing I changed in my code is I removed the parent table relations and it works fine now..
I would also like to let  you and your team know that I like using RadControls and I think they are great , very helpful and handy.
Keep up your good work.

Thanks a lot for your support.
Payal Mandalia.
Tags
Grid
Asked by
Payal Mandalia
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Payal Mandalia
Top achievements
Rank 1
Share this question
or