I have a gridview containing some data from db, and after a check I want to see a small cross/tick image in each row, due to the result of the check.How can I change the image url dynamically?
A:
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="check" runat="server" ImageUrl='<%#If(Eval("check") = 1,"images/checked.gif","images/unchceked.gif") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
gfrizzle
2008-10-30 20:25:49
A:
This doesnt work.
Compiler Error Message: CS1525: Invalid expression term 'If'
chris
2010-03-09 16:34:44
+2
A:
You could either use inline statement like
<%#Eval("check").ToString() == "1" ? "images/checked.gif" : "images/unchceked.gif")%>
or use a function to get the result as follows:
<%# getImageUrl(Eval("value")) %>
Public Function getImageUrl(ByVal value As Integer) As String
If value = 0 Then
Return "images/unchceked.gif"
Else
Return "mages/checked.gif"
End If
End Function
Chinjoo
2010-09-11 03:11:12