views:

140

answers:

1

Compiler Error Message: CS0030: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ImageField'

Line 107:    protected void BookListView_DataBinding(object sender, EventArgs e)
Line 108:    {
Line 109:        ImageField img = (ImageField)BookListView.FindControlR("Image1");
Line 110:        if (img.ImageUrl == "")
Line 111:            img.ImageUrl = "Snoimage.gif";

the control is find but ...

error occured in line 109

FindControlR is an extension to find the control

the control is located in a listview

<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Pic_Address") %>' />
A: 

You're trying to cast an Image control to an ImageField control.

Try modifying your code slightly:

Image img = (Image)BookListView.FindControlR("Image1");
Lance McNearney
i want to access the ImageUrl property of the image control, the problem is i cant access the control.FindControlR returns control,i want to know how to cast it to imagefield so i can set the ImageUrl in the code behind.
Mahdi
Your code is already casting the Control to an ImageField. The reason it's throwing the exception is because you're trying to cast the Image control (ASP:Image) to an ImageField (ASP:ImageField). Either modify your casting code or modify the front-end code to use ASP:ImageField.
Lance McNearney