tags:

views:

1278

answers:

3

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
A: 

This doesnt work.

Compiler Error Message: CS1525: Invalid expression term 'If'

chris
+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