Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid Binding Error "Object does not match target type"

Reply
Thread Tools

Datagrid Binding Error "Object does not match target type"

 
 
Karahan Celikel
Guest
Posts: n/a
 
      08-19-2003
I have a datagrid in which I want to visualize objects of various type
(they inherit from the same base class). I want to display common properties
of the objects over the grid.

At runtime I create an ArrayList that contains all the objects . When I make
the binding I obtain the following error:

Object does not match target type.

Exception Details: System.Reflection.TargetException: Object does not match
target type.

Any help would be appreciated.

Thanks.









 
Reply With Quote
 
 
 
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      08-20-2003

Hi Karahan,

When binding the data grid to an array list the binding mechanism looks for
the type of the first item in the list and uses the property descriptors
collection for that type. If the controls in the array list are various
types, an ¡°Object does not match target type.¡± error will be thrown out.

You may check the following link for more information.

Databind ArrayList to DataGrid
<http://groups.google.com/groups?hl=e...hreadm=eJwevg%
23gCHA.2108%40tkmsftngp12&rnum=3&prev=/groups%3Fq%3DDatagrid%2BBinding%2BErr
or%2B%2522Object%2Bdoes%2Bnot%2Bmatch%2Btarget%2Bt ype%2522%26hl%3Den%26lr%3D
%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DeJwevg%2523gCHA.2108%2540tkmsftngp12%26 r
num%3D3>

To walk around this, you may add these controls programmatically form code
in DataGrid.ItemCreated event. Here is a code snippet. You may modify it to
meet your requirements.

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
e.Item.Cells [0].Controls .Add (new Button());
}
else if(e.Item.ItemIndex == 2)
{
e.Item.Cells [2].Controls.Add(new DropDownList());
}
else if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Cells [1].Controls.Add(new TextBox ());
}
}

Check the below link for more information.

DataGrid.ItemCreated Event
<http://msdn.microsoft.com/library/de...-us/cpref/html
/frlrfsystemwebuiwebcontrolsdatagridclassitemcreate dtopic.asp>

Hope this helps.

Best regards,
Lewis

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Karahan Celikel" <(E-Mail Removed)>
| Subject: Datagrid Binding Error "Object does not match target type"
| Date: Tue, 19 Aug 2003 09:49:18 -0500
| Lines: 24
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| NNTP-Posting-Host: 126-23-206.biztyp2.ksle.everestkc.net 64.126.23.206
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridc ontrol:6259
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
|
| I have a datagrid in which I want to visualize objects of various type
| (they inherit from the same base class). I want to display common
properties
| of the objects over the grid.
|
| At runtime I create an ArrayList that contains all the objects . When I
make
| the binding I obtain the following error:
|
| Object does not match target type.
|
| Exception Details: System.Reflection.TargetException: Object does not
match
| target type.
|
| Any help would be appreciated.
|
| Thanks.
|
|
|
|
|
|
|
|
|
|

 
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
Need help, get error "Object does not match target type" in one instanceof an app, when others work Lasse Vågsæther Karlsen ASP .Net 1 11-27-2007 02:46 PM
Object does not match target type. rn5a@rediffmail.com ASP .Net 4 02-21-2007 01:57 PM
"gridview Object does not match target type" error during binding collection of different type object gui.besse@gmail.com ASP .Net 2 08-06-2006 03:12 PM
Datagrid Binding Error: "Object does not match target type." Karahan Celikel ASP .Net Building Controls 1 08-20-2003 12:57 PM
DataGrid Binding Problem : "Object does not match target type." Karahan Celikel ASP .Net Web Controls 1 08-20-2003 12:56 PM



Advertisments