Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Binding Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike McIntyre - 24 Jul 2007 18:51 GMT
Hi,

1. In a class named DBUser there is a property named FullNameByLastName.
This property does not have a backing field.  It combines two backing fields
an returns a string result:

       public virtual string FullNameByLastName
       {
           get
           {
               return m_LastName + ", " + m_FirstName;
           }
       }

2. An ObjectDataSource is used. Its SelectMethod returns a generic
collection ( List<DBUser>)

3. The ObjectDataSource is assigned/bound to a GridView.

4. FullNameByLastName is bound to a column in the GridView.

   <asp:GridView ID="ListGridView" runat="server">
       <Columns>
           <asp:BoundField
               DataField="FullNameByLastName"
               SortExpression="FullNameByLastName"
               HeaderStyle-HorizontalAlign="Left"
               ItemStyle-HorizontalAlign="Left"
   HeaderText="<%$Label:TITLE %>"
           />
           Etc...

The exception I get is shown below. In brief it is: 'FullNameByLastName' on
object 'WorkforceLogic.Core.Domain.DBUser' threw the following
exception:'Object does not match target type.']

I only get this exception on class properties what don't have backing fields
such as LastNameByFullName.  All other fields bind without the exception.

What do you think?  Is this an issue with ObjectDataSource, GridView, or the
NHibernate?  Or?

Best Regards,

Signature

Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com

[TargetException: Object does not match target type.]
  System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
+2284281
  System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean
skipVisibilityChecks) +114
  System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
  System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object
component) +86

[TargetInvocationException: Property accessor 'FullNameByLastName' on object
'WorkforceLogic.Core.Domain.DBUser' threw the following exception:'Object
does not match target type.']
  System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object
component) +370
  System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer)
+201
  System.Web.UI.WebControls.BoundField.OnDataBindField(Object sender,
EventArgs e) +60
  System.Web.UI.Control.OnDataBinding(EventArgs e) +99
  System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +206
  System.Web.UI.Control.DataBind() +12
  System.Web.UI.Control.DataBindChildren() +216
  System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216
  System.Web.UI.Control.DataBind() +12
  System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32
dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState,
Boolean dataBind, Object dataItem, DataControlField[] fields,
TableRowCollection rows, PagedDataSource pagedDataSource) +221
  System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding) +3004
  System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data) +59
  System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
+11
  System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data) +111
  System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback) +29
  System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
  System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
  System.Web.UI.WebControls.GridView.DataBind() +4
  System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
  System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
+69
  System.Web.UI.Control.EnsureChildControls() +87
  System.Web.UI.Control.PreRenderRecursiveInternal() +41
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

Sergey Poberezovskiy - 25 Jul 2007 06:40 GMT
Mike,

Just a guess - try to add a setter to your property - as binding assumes two
directional traffic. As your property is calculated, you can leave it empty,
but it may make the grid happier  :-)

> Hi,
>
[quoted text clipped - 39 lines]
>
> Best Regards,
Mike McIntyre - 25 Jul 2007 16:47 GMT
Thanks Sergey.

I added a setter but it did not solve the problem.

Now I am looking at whether I can map the property, which is only in the
class and not associted with a database column, in the NHibernate xml
mapping file.

Signature

Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com

> Mike,
>
[quoted text clipped - 51 lines]
>>
>> Best Regards,

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.