HighTechTalks DotNet Forums  

Invalid Cast in Custom DataGridTemplate

Dotnet Data Tools microsoft.public.dotnet.datatools


Discuss Invalid Cast in Custom DataGridTemplate in the Dotnet Data Tools forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default Invalid Cast in Custom DataGridTemplate - 11-03-2005 , 11:06 AM






Hi folks,

I am trying to create a custom tenmplate for a web based DataGrid.

Code here >

public class ShopListImageTemplate : ITemplate{

public void InstantiateIn(Control container) {
Image img = new Image();
img.DataBinding += new EventHandler(this.BindImage);
container.Controls.Add(img);
}

private void BindImage(object sender, EventArgs e) {
Image img = (Image)sender;
DataGridItem container = (DataGridItem)img.NamingContainer;
img.ImageUrl =
((DataRowView)container.DataItem)["ImageName"].ToString();
}

}

I am getting an invalid cast exception in the web app that uses this
grid upon a call to DataBind. I got this code from an article by Dino
Esposito and have also seen the exact same code on msdn.

Completely confused as to what the problem might be as it seems to make
sense from a conceptual stand point.

Any help greatly appreciated.

Many Thanks

Simon


Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default Re: Invalid Cast in Custom DataGridTemplate - 11-03-2005 , 11:08 AM






..NET 1.1 BTW.

Cheers

Simon


Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: Invalid Cast in Custom DataGridTemplate - 11-03-2005 , 11:34 AM



Solved, the cast the to DataRowView is onyl valid of the DataSource is
a DataView. As my data source is a strongly typed collection I need to
cast to my collection instead.

Cheers

Simon


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.