How do I conditionally set the imageurl property of an ASP:IMAGE control in a GridTemplateColumn?
I can clear the controls to remove the image completely, but am unsure how to cast the Controls(0) collection to get an ASP:IMAGE object? I have tried casting to Image, but this obviously isnt an ASP:IMAGE type, but something from Graphics.
I can do conditional formatting like this, but want to do it programatically as I may want to plug in different images:
<
rad:GridTemplateColumn UniqueName="ButtonColumn">
<ItemTemplate>
<asp:Image runat="server" ImageUrl='<%# IIF(TypeOf Eval("SDC_A") Is System.DBNull, "~/Images/warning.gif","~/Images/tick.gif") %>' Width="10" Height="10"/>
</ItemTemplate>
</rad:GridTemplateColumn>
Protected
Sub grdStudyMilestones_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles grdStudyMilestones.ItemDataBound
'Is it a GridDataItem
If (TypeOf (e.Item) Is GridDataItem) Then
'Get the instance of the right type
Dim dataBoundItem As GridDataItem = e.Item
'Check the formatting condition
If IsDate(dataBoundItem("SDC_A").Text) Then
dataBoundItem(
"SDC").BackColor = Color.Gray
Else
' NEED TO ACCESS THE CONTROL SPECIFICALLY
dataBoundItem(
"ButtonColumn").Controls.Clear()
End If
End If
End Sub