Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi have image in gridview


ASP.NET
<ItemTemplate><asp:Image ID="Img_Pic" runat="server" ImageUrl='<%#Bind("Pic")%>' Width="100" Height="100" /> </ItemTemplate>


and i bind data from server side to gridview
C#
GridView1.DataSource = dt;
GridView1.DataBind();


in event GridView1_OnRowDeleting i can access to id field gridview in event
and delet rows from databse
i want too get imageurl for delete file from folder:
C#
int id = Convert.ToInt32(((Label)GridView1.Rows[e.RowIndex].FindControl("lbl_ID_LghtBx")).Text);
 Image a = ((Image) GridView1.Rows[e.RowIndex].FindControl("Img_Pic"));

FileInfo myfileinf = new FileInfo("~/img/LghtBx") + "/" + Pic.FileName);
 myfileinf.Delete();


but i get error in Image a = ((Image) GridView1.Rows[e.RowIndex].FindControl("Img_Pic")):
Error 5 'Image' is an ambiguous reference between 'System.Drawing.Image' and 'System.Web.UI.WebControls.Image'
Posted

The error tells you exactly what is wrong, which is to tell the application what "Image" class to use so use following code and check your problem will resolve.
C#
System.Drawing.Image a = ((System.Drawing.Image) GridView1.Rows[e.RowIndex].FindControl("Img_Pic"));
 
Share this answer
 
v3
Error 5 'Image' is an ambiguous reference between 'System.Drawing.Image' and 'System.Web.UI.WebControls.Image'
Based on which Image control you have used, please update the line of code accordingly. Most probably you are using Image web control and if so, the code should be:
C#
Image a = ((System.Web.UI.WebControls.Image) GridView1.Rows[e.RowIndex].FindControl("Img_Pic")):


Error above just tells that compiler is unable to understand which Image you are talking of.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900