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