Help plz !!!Binding image in gridview dynamically.

  • Thread starter Thread starter sanju
  • Start date Start date
S

sanju

Hi,

I am struggling to find a way to bind image to gridview template field based
on the bool value of database field.

my requirement is ..

i have a field "IsNewMessage" in "Messages" table .

and i am binding data to gridview "sqldatasource". I want to display
"NewMessage.gif" if the database fieldvalue is True or else
"OldMessage.gif" .


<asp:templatefield headertext="Received From">

<itemtemplate>

<asp:label id="lblName"

text= '<%# Eval("IsNewMessage") %>'

runat="server"/>

</itemtemplate>

<ItemStyle Width="100px" />

Thank you
sanju
 
Use code instead in the ItemDataBound find image control and load the pic
you want.
There is another trick to do it is to call your images true.gif and
false.gif then bind it this way

<asp:Image ImageUrl='<%# Eval("IsNewMessage","{0}.gif") %>' runat=server>

Where IsNewMessage is a boolean(bit)..
Why you use a label?!
 
Back
Top