I'm having trouble with sorting child collections on my web pages.
I have the following classes:
I used NameInfoList as the data source for a GridView and implemented the sorting feature on it. Here's the C# code snippet where I return the sorted list:
private SortedBindingList<The.Library.NameInfo> GetNameInfoList()
{
object obj = Session[GetCurrentObjectCacheName()];
if ( obj == null
|| !(obj is SortedBindingList<The.Library.NameInfo>)
)
{
// Set parameter values.
string parentName = tbxSearch.Text + "%";
NameInfoList list = NameInfoList.GetList(parentName);
obj = new SortedBindingList<NameInfo>
(NameInfoList.GetList(parentName));
HttpContext.Current.Session[GetCurrentObjectCacheName()] = obj;
}
return ((SortedBindingList<The.Library.NameInfo>)obj);
}
Works like a charm!
Here's my problem. I have a "master object", one of whose properties is a NameInfoList. That NameInfoList is in a GridView on the same page with the master object. I want to enable sorting on the NameInfoList grid on this page also. To avoid lots of round-trips, the master object is responsible for populating all the data that's inside it. So, my cache is actually the master object , not a NameInfoList object.
Here's the error I'm getting:
Unable to cast object of type 'The.Library.NameInfoList' to type 'Csla.SortedBindingList`1[The.Library.NameInfo]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'The.Library.NameInfoList' to type 'Csla.SortedBindingList`1[The.Library.NameInfo]'.
Source Error:
Line 93: Main obj = GetMain();
<-- Note: My NameInfoList in Main is called Names -->
Line 94: Object names = obj.Names;
Line 95: return ((SortedBindingList<The.Library.NameInfo>)names);
Line 96: }
Line 97: #endregion
Source File: c:\Inetpub\wwwroot\TheWeb\DataReports\Detail.aspx.cs Line: 95
Stack Trace:
[InvalidCastException: Unable to cast object of type 'The.Library.NameInfoList' to type 'Csla.SortedBindingList`1[The.Library.NameInfo]'.]
DataReports_Detail.GetNames() in c:\Inetpub\wwwroot\TheWeb\DataReports\Detail.aspx.cs:95
DataReports_Detail.NameDS_SelectObject(Object sender, SelectObjectArgs e) in c:\Inetpub\wwwroot\TheWeb\DataReports\Detail.aspx.cs:82
Csla.Web.CslaDataSource.OnSelectObject(SelectObjectArgs e) in C:\MyProj\Csla\Web\CslaDataSource.cs:123
Csla.Web.CslaDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) in C:\MyProj\Csla\Web\CslaDataSourceView.cs:60
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +84
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.GridView.DataBind() +23
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +92
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +100
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4437
Here's the code returning the sorted binding list...
private SortedBindingList<The.Library.NameInfo> GetNames()
{
UICMain obj = GetUICMain();
Object names = obj.Names; // .Names is a NameInfoList class.
return ((SortedBindingList<UIC.Library.UICNameInfo>)names);
}
Frankly, I'm confused. :)
Copyright (c) Marimer LLC