asp:Image control in a DataList ItemDataBound event

I have " <asp:Image ID="imgEng" Visible=False . .> " in a DataList

I'm trying to reference it so I can set it's visible to True but can't.
This is not working,  "Image" is a problem.  in ItemDataBound event:

   Dim imgEng As Image  << not valid
   imgEng = e.Item.Cells(3).FindControl("imgEng")
   imgEng.Visible = True

Tried this but got the same problem:

   Dim imgEngAs Image = CType(e.Item.Cells(3).FindControl("imgEng"), Image)

But controls like this work:

         Dim lnkAdd As LinkButton
         lnkAdd = e.Item.Cells(3).FindControl("lnkAdd")
         lnkAdd.Visible = True

How is a asp:Image control referenced in a DataList?
LVL 16
MikeMCSDAsked:
Who is Participating?
 
b1xml2Connect With a Mentor Commented:
ahhh it may be because there is the namespace System.Drawing and System.Web.UI.WebControls clashing!!

Dim imgEng As System.Web.UI.WebControls.Image = DirectCast(e.Item.FindControl("imgEng"),System.Web.UI.WebControls.Image)

0
 
b1xml2Commented:
Public Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
      Select Case e.Item.ItemType
      Case ListItemType.Item, ListItemType.AlternatingItem
            Dim imgEng As Image = DirectCast(e.Item.FindControl("imgEng"),Image)
      End Select
End Sub

<asp:DataList Id="DataLust1" RunAt="Server" OnItemDataBound="DataList1_ItemDataBound">

</asp:DataList>
0
 
MikeMCSDAuthor Commented:
Tried this but same problem:
Dim imgEng As Image = DirectCast(e.Item.Cells(3).FindControl("imgEng"), Image)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
b1xml2Commented:
there's a slight difference:
Dim imgEng As Image = DirectCast(e.Item.FindControl("imgEng"),Image)

The CellCollection starts at 0. So the first column is e.Item.Cells(0) .. and so on and so forth. To avoid worrying about which cell the control is in, use e.Item.FindControl(..)

HTH
0
 
MikeMCSDAuthor Commented:
This is the problem:
Dim imgEng As Image   <<< it won't let me declare it . .  look at it in VS.
0
 
b1xml2Commented:
where System.Drawing and System.Web.UI.WebControls are referenced within the same class, there will be a clash with the class Image (both namespaces have their respective Image class)

In intellisense inside C#, the red error icon appears when you try to type Image. This apparently is not available in the VB.NET IDE... very strange
0
 
MikeMCSDAuthor Commented:
very good, yes b1, it looks like that is the problem . . but why did they name the control
for asp:Image with namespace Image?  To drive me crazy of course.

I came up with another idea/solution in the meantime that also worked:

<asp:Image ID="imgEng" Visible='<%# DataBinder.Eval(Container, "DataItem.Engraving")%>'  . . .   the field is a bit field.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.