Help plz !!!Binding image in gridview dynamically.

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
 
I

Islamegy®

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?!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top