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

List sub object sorting and grouping issues

2 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tlp
Top achievements
Rank 1
tlp asked on 19 Aug 2008, 12:22 AM

I am creating a grid programmatically within a page. The datasource is an object list in which the objects contain lists as sub-objects.

An example of the object used within the list is as follows:

public class TaskView  
 
{
#region Private Variables  
 
private string _projectName;  
private string _projectCode;  
private string _taskCode;  
private string _taskName;  
 
private List<string> _dataTypeHeaderNameList;  
private List<string> _dataTypeNameList;  
private List<decimal> _dataTypeDataList;
#endregion  
 
   
 
#region Constructors  
 
// Constructors  
 
public TaskView()  
 
{  
 
}
#endregion  
 
   
 
#region Properties  
 
public string ProjectCode  
 
{  
get { return _projectCode; }  
set { _projectCode = value; }  
}  
 
public string ProjectName  
 
{  
get { return _projectName; }  
set { _projectName = value; }  
}  
 
 
public string TaskCode  
 
{  
get { return _taskCode; }  
set { _taskCode = value; }  
}  
 
public string TaskName  
 
{  
get { return _taskName; }  
set { _taskName = value; }  
}   
 
public List<string> DataTypeHeaderNameList  
 
{  
get { return _dataTypeHeaderNameList; }  
set { _dataTypeHeaderNameList = value; }  
}  
 
public List<string> DataTypeNameList  
 
{  
get { return _dataTypeNameList; }  
set { _dataTypeNameList = value; }  
}  
 
public List<decimal> DataTypeDataList  
 
{  
get { return _dataTypeDataList; }  
set { _dataTypeDataList = value; }  
}
#endregion  
 
}  
 

The columns within the grid are created based on the above object. Basically, columns are created for ProjectName, TaskName, and the number of items within the DataTypeNameList. The code snippet for creating the columns is as follows:

        boundColumn = new GridBoundColumn();  
        RadGridTaskView.MasterTableView.Columns.Add(boundColumn);  
        boundColumn.UniqueName = "ProjectName";  
        boundColumn.DataField = "ProjectName";  
        boundColumn.HeaderText = "Project Name";  
        boundColumn.Aggregate = GridAggregateFunction.None;  
 
 
        boundColumn = new GridBoundColumn();  
        RadGridTaskView.MasterTableView.Columns.Add(boundColumn);  
        boundColumn.UniqueName = "TaskName";  
        boundColumn.DataField = "TaskName";  
        boundColumn.HeaderText = "Task";  
        boundColumn.Aggregate = GridAggregateFunction.None;  
 
 
        for (int i = 0; i < criteria.CostDataList.Count; i++)  
        {  
            boundColumn = new GridBoundColumn();  
            RadGridTaskView.MasterTableView.Columns.Add(boundColumn);  
            boundColumn.UniqueName = criteria.CostDataList[i];  
            boundColumn.DataField = "DataTypeDataList[" + i.ToString() + "]";  
            boundColumn.HeaderText = criteria.CostDataList[i];  
            boundColumn.DataFormatString = "{0:#,###.00}";  
            boundColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Right;  
            boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Right;  
            boundColumn.DataType = Type.GetType("System.Decimal"false);  
            boundColumn.Aggregate = GridAggregateFunction.Sum;  
            boundColumn.FooterText = "Total:";  
        } 

When the page is loaded and at least one item is in the DataTypeDataList the following exception is thrown:

System.Data.SyntaxErrorException was unhandled by user code  
  Message="Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier." 
  Source="System.Data" 
  StackTrace:  
       at System.Data.ExpressionParser.ParseAggregateArgument(FunctionId aggregate)  
       at System.Data.ExpressionParser.Parse()  
       at System.Data.DataExpression..ctor(DataTable table, String expression, Type type)  
       at System.Data.DataTable.Compute(String expression, String filter)  
       at Telerik.Web.UI.GridBoundColumn.ApplyAggregates(TableCell cell, String footerText)  
       at Telerik.Web.UI.GridBoundColumn.cell_DataBinding(Object sender, EventArgs e)  
       at System.Web.UI.Control.OnDataBinding(EventArgs e)  
       at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)  
       at System.Web.UI.Control.DataBind()  
       at System.Web.UI.Control.DataBindChildren()  
       at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)  
       at System.Web.UI.Control.DataBind()  
       at Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows)  
       at Telerik.Web.UI.GridTableView.CreateFooterItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTFoot tfoot)  
       at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)  
       at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)  
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)  
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)  
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)  
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()  
       at Telerik.Web.UI.GridTableView.PerformSelect()  
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()  
       at Telerik.Web.UI.GridTableView.DataBind()  
       at Telerik.Web.UI.RadGrid.DataBind()  
       at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)  
       at Telerik.Web.UI.RadGrid.Rebind()  
       at View_TaskView.HierarchyDataViewCriteria_Submit(Object sender, EventArgs e) in d:\Documents and Settings\TLP\My Documents\Visual Studio 2005\Projects\Athena\AthenaWeb\View\TaskView.aspx.cs:line 366  
       at UserControls_DataViewCriteria.OnSubmit(EventArgs e) in d:\Documents and Settings\TLP\My Documents\Visual Studio 2005\Projects\Athena\AthenaWeb\UserControls\DataViewCriteria.ascx.cs:line 68  
       at UserControls_DataViewCriteria.ButtonSubmit_Click(Object sender, EventArgs e) in d:\Documents and Settings\TLP\My Documents\Visual Studio 2005\Projects\Athena\AthenaWeb\UserControls\DataViewCriteria.ascx.cs:line 352  
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)  
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)  
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)  
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)  
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)  
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
 

If I set the grid bound column aggregate property to None (instead of Sum)  within the loop that is creating the columns, the grid is created without errors.

When the grid is created successfully (i.e., with the aggregate property set to None), and I attempt to sort on one of the columns that is created within the for loop, I get the following error when I click on the column header to invoke the sort:

Cannot find column DataTypeDataList[0]

Any help in resolving the above issues would be greatly appreciated.


Thanks, Tony


2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Aug 2008, 01:46 PM
Hello Tony,

The most probable reason is that RadGrid is unable to get the your sub-object because the index itself is not a bindable property. The recommended way is to use sub-objects as shown in this help article:
Tips when binding to custom collections

I would also like to suggest you to bind the same collection to the ASP.NET GridView and let us know what happened.
Alternatively you can send us simplified and runnable version of your project in order to examine it locally and then give you the appropriate answer. You can attach the code to regular support ticket.

Kind Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
tlp
Top achievements
Rank 1
answered on 23 Aug 2008, 08:31 AM
Daniel,

Thanks for your response. For the moment, I have a solution that works. Basically, I modified the list objects within the object collection to expose the indexed values as separate properties. This works fine but I had set a limit on the number of dynamic columns that can be generated.

Time permitting, I will provide a sample project for your examination.


Thanks,

Tony
Tags
Grid
Asked by
tlp
Top achievements
Rank 1
Answers by
Daniel
Telerik team
tlp
Top achievements
Rank 1
Share this question
or