473,467 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Gridview and column with variable image

Hi group,

I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSource.
The SelectMethod of the datasource returns a list of Customer objects.
Each Customer object has a property "Notes".

When I display the list of customers in the gridview, I would like to
provide a column that displays an Image associated with the Notes
property. If the Notes property contains data I want to display a
colored version of the image. When the Notes property doesn't contain
data I want to display a grayed version of the image.
Clicking an image should launch a URL to either view or enter notes.

A variation on this (for another column in the same grid) is the need
to display one of several images or no image at all, based on the
value of a property.
If a customer's Status property = Yes, display a green image;
If a customer's Status property = No, display a red image;
If a customer's Status property = Maybe, display a yellow image;
If a customer's Status property = Done, don't display an image;

This behavior is similar to Hotmail's classic display of the message
icon in the first column, which changed based on whether a message is
flagged read, unread, replied to, unknown sender, ...

Does anyone have any suggestions on how to implement this or can
anyone point me to an article that explains this?

Thanks
-- Hans

Jul 20 '07 #1
3 4967

"Froefel" <ha************@gmail.comwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...
Hi group,

I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSource.
The SelectMethod of the datasource returns a list of Customer objects.
Each Customer object has a property "Notes".

When I display the list of customers in the gridview, I would like to
provide a column that displays an Image associated with the Notes
property. If the Notes property contains data I want to display a
colored version of the image. When the Notes property doesn't contain
data I want to display a grayed version of the image.
Clicking an image should launch a URL to either view or enter notes.

A variation on this (for another column in the same grid) is the need
to display one of several images or no image at all, based on the
value of a property.
If a customer's Status property = Yes, display a green image;
If a customer's Status property = No, display a red image;
If a customer's Status property = Maybe, display a yellow image;
If a customer's Status property = Done, don't display an image;

This behavior is similar to Hotmail's classic display of the message
icon in the first column, which changed based on whether a message is
flagged read, unread, replied to, unknown sender, ...

Does anyone have any suggestions on how to implement this or can
anyone point me to an article that explains this?

Thanks
-- Hans
Hi, Hans

the easiest way is to have 4 images: yes.gif, no.gif, maybe.gif and done.gif
and use a value of the Status to build a name of the image:

<asp:TemplateColumn>
<ItemTemplate>
<%#"<img src=""" & DataBinder.Eval(Container.DataItem, "Status") &
".gif"">"%>
</ItemTemplate>
</asp:TemplateColumn>

another option is to make a method

public string getImage(object s)
{
if (s == "Yes") {
return("<img=....");
}
.....
}

and use it to get an image

<asp:TemplateColumn>
<ItemTemplate>
<%# getImage(Container.DataItem, "Status")) %>
</ItemTemplate>
</asp:TemplateColumn>

Hope this helps
Jul 20 '07 #2
Hi Alex,

Yep, that does it. Meanwhile I found a few articles and they confirmed
your suggestions. I've implemented it and got it to work... at least
the basics of displaying the image. In fact, I managed to display a
dynamic image in an asp:ImageField, but because it cannot have a
hyperlink associated with it, I also got it to work with a
asp:ButtonField of Type="image". The ButtonField is clickable through
the CommandName argument, but I still have to find out how to respond
to that.
I'll probably have some questions about that shortly.

Thanks for the hints.
On Jul 20, 7:56 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
"Froefel" <hansdeschry...@gmail.comwrote in message

news:11**********************@n60g2000hse.googlegr oups.com...
Hi group,
I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSource.
The SelectMethod of the datasource returns a list of Customer objects.
Each Customer object has a property "Notes".
When I display the list of customers in the gridview, I would like to
provide a column that displays an Image associated with the Notes
property. If the Notes property contains data I want to display a
colored version of the image. When the Notes property doesn't contain
data I want to display a grayed version of the image.
Clicking an image should launch a URL to either view or enter notes.
A variation on this (for another column in the same grid) is the need
to display one of several images or no image at all, based on the
value of a property.
If a customer's Status property = Yes, display a green image;
If a customer's Status property = No, display a red image;
If a customer's Status property = Maybe, display a yellow image;
If a customer's Status property = Done, don't display an image;
This behavior is similar to Hotmail's classic display of the message
icon in the first column, which changed based on whether a message is
flagged read, unread, replied to, unknown sender, ...
Does anyone have any suggestions on how to implement this or can
anyone point me to an article that explains this?
Thanks
-- Hans

Hi, Hans

the easiest way is to have 4 images: yes.gif, no.gif, maybe.gif and done.gif
and use a value of the Status to build a name of the image:

<asp:TemplateColumn>
<ItemTemplate>
<%#"<img src=""" & DataBinder.Eval(Container.DataItem, "Status") &
".gif"">"%>
</ItemTemplate>
</asp:TemplateColumn>

another option is to make a method

public string getImage(object s)
{
if (s == "Yes") {
return("<img=....");

}
....
}

and use it to get an image

<asp:TemplateColumn>
<ItemTemplate>
<%# getImage(Container.DataItem, "Status")) %>
</ItemTemplate>
</asp:TemplateColumn>

Hope this helps

Jul 21 '07 #3
Here's a code sample from ASPNEt101.com:
http://aspnet101.com/aspnet101/aspne...ditionalImages

It's all done in the RowDatabound event

David Wier
http://aspnet101.com
http://iWritePro.com - one click PDF/DocToHTML/RTFtoPDF

"Froefel" <ha************@gmail.comwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...
Hi group,

I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSource.
The SelectMethod of the datasource returns a list of Customer objects.
Each Customer object has a property "Notes".

When I display the list of customers in the gridview, I would like to
provide a column that displays an Image associated with the Notes
property. If the Notes property contains data I want to display a
colored version of the image. When the Notes property doesn't contain
data I want to display a grayed version of the image.
Clicking an image should launch a URL to either view or enter notes.

A variation on this (for another column in the same grid) is the need
to display one of several images or no image at all, based on the
value of a property.
If a customer's Status property = Yes, display a green image;
If a customer's Status property = No, display a red image;
If a customer's Status property = Maybe, display a yellow image;
If a customer's Status property = Done, don't display an image;

This behavior is similar to Hotmail's classic display of the message
icon in the first column, which changed based on whether a message is
flagged read, unread, replied to, unknown sender, ...

Does anyone have any suggestions on how to implement this or can
anyone point me to an article that explains this?

Thanks
-- Hans

Jul 21 '07 #4

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

Similar topics

1
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
1
by: Miguel Dias Moura | last post by:
Hello, I have a dataset with 2 fields, (String) and (Boolean). I want to add, FROM the ASPX.VB Code, 2 columns: 1. Column which will display the Text field. I need this column to recognize...
3
by: Dave Bareham | last post by:
I'm fairly new to this so bear with me! I have created a gridview in an aspx page which successfully talks to a SQL backend via a datasource. One of the colums contains a reference to an image...
1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
1
by: silpa | last post by:
Hi, I have a gridview. It has two columns.first column contains a thread. Second column contains an image which is of type buttonfield to close this thread which is shown below. The image is a...
10
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the...
0
by: =?Utf-8?B?RWR3YXJkSA==?= | last post by:
In Gridview I have column representing Thumbnail image which works fine.: <asp:ImageField DataImageUrlField="PicFile1" DataImageUrlFormatString="Images/A009/Thumbs/{0}"> </asp:ImageField> I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.