image in datagrid

N

nicholas

How can I show or hide an image in a datagrid depending on a field.

Something like: if myfield <> "" then 'show image' else 'show noimage.gif'
end if

the image field contains the image name
so: 'show image' could be something like <img source="/myfolder<%#
databinder.eval(....) %>" ..... >

THX
 
G

Guest

Override the Item Data Bound event and check the other field in the datagrid
item event args.

You could also add a custom field to the dataset you are binding to that
lists the values for the image and check that on databind.

HTH
 
N

nicholas

Could you explain your first proposition, I don't realy understand what you
mean.

THX a lot,
Nic
 
J

Joel Martinez

The easiest way that I've found of doing it is by setting an event
handler on the ItemDataBound event. Put a placeholder control into
your item template, pull it out on the data bound event, then do:

if (whatever)
plcHolder.Controls.Add("<img src=\"whatever.jpg\" />");

or you could even extend that concept and use an HtmlImage control
(<img runat="server" />) instead of a placeholder ... in fact, that
would be a little nicer.

Hope that helps,
Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top