[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


asp:Image control in a DataList ItemDataBound event

Posted on 2005-05-08
Medium Priority
Last Modified: 2008-03-17
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?
Question by:MikeMCSD
  • 4
  • 3
LVL 23

Expert Comment

ID: 13954817
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">

LVL 16

Author Comment

ID: 13954841
Tried this but same problem:
Dim imgEng As Image = DirectCast(e.Item.Cells(3).FindControl("imgEng"), Image)
LVL 23

Expert Comment

ID: 13954852
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(..)

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 16

Author Comment

ID: 13954873
This is the problem:
Dim imgEng As Image   <<< it won't let me declare it . .  look at it in VS.
LVL 23

Accepted Solution

b1xml2 earned 2000 total points
ID: 13954881
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)

LVL 23

Expert Comment

ID: 13954891
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
LVL 16

Author Comment

ID: 13954908
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.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question