473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

image in datagrid

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
Nov 18 '05 #1
4 1431
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

"nicholas" wrote:
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

Nov 18 '05 #2
Could you explain your first proposition, I don't realy understand what you
mean.

THX a lot,
Nic

"MikeL" <Mi***@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
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

"nicholas" wrote:
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

Nov 18 '05 #3
When you bind a dataset to a datagrid an event happens for every row that is
binded. Therefore you need to override that event and check your field(s).
Here is an article on doing this:

http://www.csharphelp.com/archives3/archive570.html

Here is another article on how to highlight a row in a datagrid. Just
switch the example to what you need to do.

http://www.dotnetjunkies.com/HowTo/C...C7478D586.dcik

HTH

MikeL

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

THX a lot,
Nic

"MikeL" <Mi***@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
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

"nicholas" wrote:
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


Nov 18 '05 #4
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

"nicholas" <mu********@hotmail.com> wrote in message news:<Oj**************@TK2MSFTNGP11.phx.gbl>...
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

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
1
by: Jim Hammond | last post by:
The code below implements two datagrid columns that display images. The first column is just a test that always displays the same image directly from a file. The second column pulls the image from...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
2
by: SQL_Klovn | last post by:
Hi! I have been struggeling for quite some time now with a stupid problem which drives me crazy. I have Datagrid, where I load some images from a SQL2000 database. This works fine, but I am not...
13
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
1
by: ltt19 | last post by:
Hi everyone! I want to do da Image gallery using just the datagrid, this one will dilpays only images, no text, that means that it will have about 4 Collumns that will displays just images from...
0
by: Tim::.. | last post by:
Please, please, please help!!! I have a datagrid that displays a list of contacts on our intranet site using the ActiveDirectory as it's main Data Source. I want to be able to show an image of...
1
by: Michael Turner | last post by:
Anyone know if you can add a background image to a datagrid, there is a property for colour but not for an image.
0
by: rockdale | last post by:
Hi, All: I dynamic add an arrow up/down image in OnItemDataBound event for my datagrid, it works fine. But I have another textbox which trigger postback and doing something, after this event get...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.