Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Databinding to custom collections

Reply
Thread Tools

Databinding to custom collections

 
 
Rob Miles
Guest
Posts: n/a
 
      11-12-2004
Hi,

I am developing a web application in ASP.NET (Visual Studio 2003, .NET
Framework v1.1.4322.573). I have a problem with databinding to a collection
of custom-defined classes.
I am trying to bind a web forms datagrid to a collection of custom classes.
The collection contains objects of an abstract type called BranchQuery. At
runtime the objects in the collection will either be of type ASRBranchQuery
or ManualBranchQuery, both of which inherit from BranchQuery. This works
fine as long as the collection contains all ASRBranchQuery objects or all
ManualBranchQuery objects. However if there is a mixture of the two runtime
types then I get the exception "System.Reflection.TargetInvocationException"
(full details at the bottom of the mail).
I cannot see why this should not work, as BranchQuery is a generalisation of
ASRBranchQuery and ManualBranchQuery and both of the implementation classes
have exactly the same method and property signatures.
I have managed to work around this so far by removing the inheritance from
my classes and replacing it with conditional statements, but this does not
strike me as good design and I would like to know whether the problem is
caused by an error on my part or a bug in the datagrid databinding?

Thanks in advance,

Rob Miles


1) Exception Information
*********************************************
Exception Type: System.Reflection.TargetInvocationException
Message: Property accessor 'EffectiveDate' on object
'IA_Online.ManualBranchQuery' threw the following exception:'Object does not
match target type.'
TargetSite: System.Object GetValue(System.Object)
HelpLink: NULL
Source: System

StackTrace Information
*********************************************
at System.ComponentModel.ReflectPropertyDescriptor.Ge tValue(Object
component)
at System.Web.UI.WebControls.BoundColumn.OnDataBindCo lumn(Object sender,
EventArgs e)
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource)
at System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean
useDataSource)
at System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
at System.Web.UI.WebControls.BaseDataList.DataBind()
at IA_Online.BranchQuerySummary.DisplayQueries() in
C:\CBP\CBP_Online\IA_Online\BranchQuerySummary.asp x.vb:line 289
at IA_Online.BranchQuerySummary.grdQueries_Load(Objec t sender, EventArgs
e) in C:\CBP\CBP_Online\IA_Online\BranchQuerySummary.asp x.vb:line 113

2) Exception Information
*********************************************
Exception Type: System.Reflection.TargetException
Message: Object does not match target type.
TargetSite: System.Object InternalInvoke(System.Object,
System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[],
System.Globalization.CultureInfo, Boolean, System.Reflection.Assembly,
Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace Information
*********************************************
at System.Reflection.RuntimeMethodInfo.InternalInvoke (Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.InternalInvoke (Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.ComponentModel.ReflectPropertyDescriptor.Ge tValue(Object
component)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding to custom properties of a custom class in ASP.NET 2 =?Utf-8?B?SW1hciBTcGFhbmphYXJz?= ASP .Net 0 04-20-2005 07:34 PM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM
Possible Bug in Lisbox.Databinding for collections Miguel Navarro ASP .Net Web Controls 2 12-08-2003 12:45 AM
Sorting collections based on nested collections Doug Poland Java 9 09-27-2003 10:46 PM
InnerProperty Persistance for Collections containing other Collections mutex ASP .Net Building Controls 0 07-27-2003 02:45 PM



Advertisments