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 |