MikeMCSD
asked on
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).FindContro l("imgEng" )
imgEng.Visible = True
Tried this but got the same problem:
Dim imgEngAs Image = CType(e.Item.Cells(3).Find Control("i mgEng"), Image)
But controls like this work:
Dim lnkAdd As LinkButton
lnkAdd = e.Item.Cells(3).FindContro l("lnkAdd" )
lnkAdd.Visible = True
How is a asp:Image control referenced 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).FindContro
imgEng.Visible = True
Tried this but got the same problem:
Dim imgEngAs Image = CType(e.Item.Cells(3).Find
But controls like this work:
Dim lnkAdd As LinkButton
lnkAdd = e.Item.Cells(3).FindContro
lnkAdd.Visible = True
How is a asp:Image control referenced in a DataList?
ASKER
Tried this but same problem:
Dim imgEng As Image = DirectCast(e.Item.Cells(3) .FindContr ol("imgEng "), Image)
Dim imgEng As Image = DirectCast(e.Item.Cells(3)
there's a slight difference:
Dim imgEng As Image = DirectCast(e.Item.FindCont rol("imgEn g"),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
Dim imgEng As Image = DirectCast(e.Item.FindCont
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
ASKER
This is the problem:
Dim imgEng As Image <<< it won't let me declare it . . look at it in VS.
Dim imgEng As Image <<< it won't let me declare it . . look at it in VS.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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.
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,
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingIt
Dim imgEng As Image = DirectCast(e.Item.FindCont
End Select
End Sub
<asp:DataList Id="DataLust1" RunAt="Server" OnItemDataBound="DataList1
</asp:DataList>