473,785 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ 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 ObjectDataSourc e.
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 4981

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

I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSourc e.
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:TemplateCo lumn>
<ItemTemplate >
<%#"<img src=""" & DataBinder.Eval (Container.Data Item, "Status") &
".gif"">"%>
</ItemTemplate>
</asp:TemplateCol umn>

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:TemplateCo lumn>
<ItemTemplate >
<%# getImage(Contai ner.DataItem, "Status")) %>
</ItemTemplate>
</asp:TemplateCol umn>

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.goo glegroups.com.. .
Hi group,
I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSourc e.
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:TemplateCo lumn>
<ItemTemplate >
<%#"<img src=""" & DataBinder.Eval (Container.Data Item, "Status") &
".gif"">"%>
</ItemTemplate>
</asp:TemplateCol umn>

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:TemplateCo lumn>
<ItemTemplate >
<%# getImage(Contai ner.DataItem, "Status")) %>
</ItemTemplate>
</asp:TemplateCol umn>

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.goo glegroups.com.. .
Hi group,

I'm looking for some help on how to achieve the following in a
gridview control that is based on an ObjectDataSourc e.
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
5887
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 image not text. I have tried all sort of things like converting the columns image to tempate so on and still could display image
8
5042
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 select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
3
13754
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. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
1
1698
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 HTML tags. The field might be something like "<h1>Heading</h1><p>Paragraph</p>
3
1487
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 which I display as a column in the grid. This works. My question is this. Can I make the image into a hyperlink so that when I click on the image it effectively causes a hyperlink equivalent to the example below.
1
9356
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 GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
1
1010
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 key icon. <asp:ButtonField ButtonType="Image" ImageUrl="~/Images/key.gif" CommandName="Close"> <ItemStyle HorizontalAlign="Center" Width="20px" /> </asp:ButtonField>
10
5771
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 images) of the gridview come from a single table/datasource. Here is my situation. In my web application, I need to display customer bills info in a gridview. Customer names and contact info are from the Customer table.
0
1534
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 want the fixed 'A009' to be replaced by Session variable - "ClCode" VB in code-behind I have: iPicFile = ImageString & Session("ClCode") & "/Thumbs/{0}" How can "iPicFile" variable be used in DataImageUrlFormatString?
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.