473,729 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically displaying images in a gridview

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.

If a customer's bill is past due, I display a red circle in the last
coumn of that row.
If a customer's bill has been paid, I display a green circle in the
last column of that row.
If a customer's bill isn't past due, I display a blue circle in the
last column of that row.

Simple, right?

These little colorful circles can be from a database table or from an
ArrayList.

I've tried a template field in the last column and then bind the
ImageUrl of the Image Control to a method I have in the code-behind,
like so:

<asp:Image ... ImageUrl='<%# GetIconPath() %>' ....></asp:Image>

It did not work.

I removed the Image control and simply tried:

<img src='GetIconPat h()' />

And it still did not work.

Then, I tried using a Label control and in the code behind I say

lblImageURL.Tex t = "<img src='" + GetIconPath() + "'/>";

It still didn't work.

Then, I created another page GetIconPath.asp x, which simply outputs
the path of the icon as a string like "~/Images/red_cirlce.jpg" , and
in the Image control, I say

<asp:Image .... ImageUrl="GetIc onPath.aspx" ... ></asp:Image>

It still refuses to work.

I tried <asp:ImageField instead of <asp:TemplateFi eld>, and it still
refuses to work. I've spent the whole day working on this, and cannot
resolve this problem.

Any hint is highly appreciated.

Sep 4 '07 #1
10 5760
<gn********@gma il.comwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
Any hint is highly appreciated.
When something like this happens, my first thought is relative paths...

Are you *absolutely sure* that the path to the various image files is
correct...?

Bear in mind that the ImageUrl property of an <asp:Imagewebco ntrol is
expecting a relative or absolute URL pointing to a graphic e.g. jpg, bmp,
gif etc:
http://msdn2.microsoft.com/en-us/lib...rl(vs.80).aspx

When you do a View Source and inspect the HTML, does that shed any light on
things...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 4 '07 #2

If it were me I'd do this in the onRowBound handler for the gridview -- that
would give you access to the data for that row. From that you could detect
the paid/late/not late status and the chance to directly drop the src into
an image tag.

john

<gn********@gma il.comwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
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.

If a customer's bill is past due, I display a red circle in the last
coumn of that row.
If a customer's bill has been paid, I display a green circle in the
last column of that row.
If a customer's bill isn't past due, I display a blue circle in the
last column of that row.

Simple, right?

These little colorful circles can be from a database table or from an
ArrayList.

I've tried a template field in the last column and then bind the
ImageUrl of the Image Control to a method I have in the code-behind,
like so:

<asp:Image ... ImageUrl='<%# GetIconPath() %>' ....></asp:Image>

It did not work.

I removed the Image control and simply tried:

<img src='GetIconPat h()' />

And it still did not work.

Then, I tried using a Label control and in the code behind I say

lblImageURL.Tex t = "<img src='" + GetIconPath() + "'/>";

It still didn't work.

Then, I created another page GetIconPath.asp x, which simply outputs
the path of the icon as a string like "~/Images/red_cirlce.jpg" , and
in the Image control, I say

<asp:Image .... ImageUrl="GetIc onPath.aspx" ... ></asp:Image>

It still refuses to work.

I tried <asp:ImageField instead of <asp:TemplateFi eld>, and it still
refuses to work. I've spent the whole day working on this, and cannot
resolve this problem.

Any hint is highly appreciated.

Sep 4 '07 #3
On Sep 4, 10:54 pm, gnewsgr...@gmai l.com wrote:
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.

If a customer's bill is past due, I display a red circle in the last
coumn of that row.
If a customer's bill has been paid, I display a green circle in the
last column of that row.
If a customer's bill isn't past due, I display a blue circle in the
last column of that row.

Simple, right?

These little colorful circles can be from a database table or from an
ArrayList.

I've tried a template field in the last column and then bind the
ImageUrl of the Image Control to a method I have in the code-behind,
like so:

<asp:Image ... ImageUrl='<%# GetIconPath() %>' ....></asp:Image>

It did not work.

I removed the Image control and simply tried:

<img src='GetIconPat h()' />

And it still did not work.

Then, I tried using a Label control and in the code behind I say

lblImageURL.Tex t = "<img src='" + GetIconPath() + "'/>";

It still didn't work.

Then, I created another page GetIconPath.asp x, which simply outputs
the path of the icon as a string like "~/Images/red_cirlce.jpg" , and
in the Image control, I say

<asp:Image .... ImageUrl="GetIc onPath.aspx" ... ></asp:Image>

It still refuses to work.

I tried <asp:ImageField instead of <asp:TemplateFi eld>, and it still
refuses to work. I've spent the whole day working on this, and cannot
resolve this problem.

Any hint is highly appreciated.
For example

<asp:TemplateCo lumn>
<ItemTemplate >
<%#"<img src='" + GetIconPath() + "'>"%>
</ItemTemplate>
</asp:TemplateCol umn>
Sep 4 '07 #4
If "~/Images/red_cirlce.jpg" is assigned to client side <imgtag,
browser wont understand ~

If it is assigned to any Url type server control (as Image.ImageUrl) ,
server would translate ~ according to folder of page/user-control
containing this control, which may have relative path to images folder
different than the page being rendered on client-side.

Try using path relative to client page (with . or .. if needed). That
may give intellisense red-line on server code, but it would get
rendered properly on client-side.

Sep 5 '07 #5
On Sep 4, 5:22 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
<gnewsgr...@gma il.comwrote in message

news:11******** **************@ 57g2000hsv.goog legroups.com...
Any hint is highly appreciated.

When something like this happens, my first thought is relative paths...

Are you *absolutely sure* that the path to the various image files is
correct...?

Bear in mind that the ImageUrl property of an <asp:Imagewebco ntrol is
expecting a relative or absolute URL pointing to a graphic e.g. jpg, bmp,
gif etc:http://msdn2.microsoft.com/en-us/lib...webcontrols.im...

When you do a View Source and inspect the HTML, does that shed any light on
things...?

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Well, path might be problem. You reminded me that I did not use
ResolveUrl anywhere in the code. May give it a try. Thx.

Sep 5 '07 #6
On Sep 4, 5:51 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On Sep 4, 10:54 pm, gnewsgr...@gmai l.com wrote:


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.
If a customer's bill is past due, I display a red circle in the last
coumn of that row.
If a customer's bill has been paid, I display a green circle in the
last column of that row.
If a customer's bill isn't past due, I display a blue circle in the
last column of that row.
Simple, right?
These little colorful circles can be from a database table or from an
ArrayList.
I've tried a template field in the last column and then bind the
ImageUrl of the Image Control to a method I have in the code-behind,
like so:
<asp:Image ... ImageUrl='<%# GetIconPath() %>' ....></asp:Image>
It did not work.
I removed the Image control and simply tried:
<img src='GetIconPat h()' />
And it still did not work.
Then, I tried using a Label control and in the code behind I say
lblImageURL.Tex t = "<img src='" + GetIconPath() + "'/>";
It still didn't work.
Then, I created another page GetIconPath.asp x, which simply outputs
the path of the icon as a string like "~/Images/red_cirlce.jpg" , and
in the Image control, I say
<asp:Image .... ImageUrl="GetIc onPath.aspx" ... ></asp:Image>
It still refuses to work.
I tried <asp:ImageField instead of <asp:TemplateFi eld>, and it still
refuses to work. I've spent the whole day working on this, and cannot
resolve this problem.
Any hint is highly appreciated.

For example

<asp:TemplateCo lumn>
<ItemTemplate >
<%#"<img src='" + GetIconPath() + "'>"%>
</ItemTemplate>
</asp:TemplateCol umn>- Hide quoted text -

- Show quoted text -
I think I did try this, and it didn't seem to work. But since if
nothing else works, I'll have to give it shot again. Thx.

Sep 5 '07 #7
On Sep 4, 8:32 pm, Muhammad Naveed Yaseen <mnyas...@gmail .comwrote:
If "~/Images/red_cirlce.jpg" is assigned to client side <imgtag,
browser wont understand ~

If it is assigned to any Url type server control (as Image.ImageUrl) ,
server would translate ~ according to folder of page/user-control
containing this control, which may have relative path to images folder
different than the page being rendered on client-side.

Try using path relative to client page (with . or .. if needed). That
may give intellisense red-line on server code, but it would get
rendered properly on client-side.
Nope, VS2005 did not show me any curly red lines. I am also
suspecting that it might be a path problem, as Mark has pointed out
also.

Sep 5 '07 #8
On Sep 4, 11:39 pm, gnewsgr...@gmai l.com wrote:
On Sep 4, 5:51 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :


On Sep 4, 10:54 pm, gnewsgr...@gmai l.com wrote:
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.
If a customer's bill is past due, I display a red circle in the last
coumn of that row.
If a customer's bill has been paid, I display a green circle in the
last column of that row.
If a customer's bill isn't past due, I display a blue circle in the
last column of that row.
Simple, right?
These little colorful circles can be from a database table or from an
ArrayList.
I've tried a template field in the last column and then bind the
ImageUrl of the Image Control to a method I have in the code-behind,
like so:
<asp:Image ... ImageUrl='<%# GetIconPath() %>' ....></asp:Image>
It did not work.
I removed the Image control and simply tried:
<img src='GetIconPat h()' />
And it still did not work.
Then, I tried using a Label control and in the code behind I say
lblImageURL.Tex t = "<img src='" + GetIconPath() + "'/>";
It still didn't work.
Then, I created another page GetIconPath.asp x, which simply outputs
the path of the icon as a string like "~/Images/red_cirlce.jpg" , and
in the Image control, I say
<asp:Image .... ImageUrl="GetIc onPath.aspx" ... ></asp:Image>
It still refuses to work.
I tried <asp:ImageField instead of <asp:TemplateFi eld>, and it still
refuses to work. I've spent the whole day working on this, and cannot
resolve this problem.
Any hint is highly appreciated.
For example
<asp:TemplateCo lumn>
<ItemTemplate >
<%#"<img src='" + GetIconPath() + "'>"%>
</ItemTemplate>
</asp:TemplateCol umn>- Hide quoted text -
- Show quoted text -

I think I did try this, and it didn't seem to work. But since if
nothing else works, I'll have to give it shot again. Thx.- Hide quoted text -

- Show quoted text -
Sentence.Remove ("since");

Sep 5 '07 #9
On Sep 5, 5:39 am, gnewsgr...@gmai l.com wrote:
On Sep 4, 5:51 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :


On Sep 4, 10:54 pm, gnewsgr...@gmai l.com wrote:
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.
If a customer's bill is past due, I display a red circle in the last
coumn of that row.
If a customer's bill has been paid, I display a green circle in the
last column of that row.
If a customer's bill isn't past due, I display a blue circle in the
last column of that row.
Simple, right?
These little colorful circles can be from a database table or from an
ArrayList.
I've tried a template field in the last column and then bind the
ImageUrl of the Image Control to a method I have in the code-behind,
like so:
<asp:Image ... ImageUrl='<%# GetIconPath() %>' ....></asp:Image>
It did not work.
I removed the Image control and simply tried:
<img src='GetIconPat h()' />
And it still did not work.
Then, I tried using a Label control and in the code behind I say
lblImageURL.Tex t = "<img src='" + GetIconPath() + "'/>";
It still didn't work.
Then, I created another page GetIconPath.asp x, which simply outputs
the path of the icon as a string like "~/Images/red_cirlce.jpg" , and
in the Image control, I say
<asp:Image .... ImageUrl="GetIc onPath.aspx" ... ></asp:Image>
It still refuses to work.
I tried <asp:ImageField instead of <asp:TemplateFi eld>, and it still
refuses to work. I've spent the whole day working on this, and cannot
resolve this problem.
Any hint is highly appreciated.
For example
<asp:TemplateCo lumn>
<ItemTemplate >
<%#"<img src='" + GetIconPath() + "'>"%>
</ItemTemplate>
</asp:TemplateCol umn>- Hide quoted text -
- Show quoted text -

I think I did try this, and it didn't seem to work. But since if
nothing else works, I'll have to give it shot again. Thx.- Hide quoted text -

- Show quoted text -
Mark told you to check the path

if you think you image is here

~/Images/red_cirlce.jpg

and your webform with the grid is here

~/webform.aspx
http://localhost/webform.aspx

Are you able to get the image as

http://localhost/Images/red_cirlce.jpg

?

When you said, that if a customer's bill is past due, it should be in
this color, if a customer's bill has been paid, then another color,
etc. you would need also to know a status of the bill, so I guess you
would need something like this

<asp:TemplateCo lumn>
<ItemTemplate >
<%#"<img src='" + GetIconPath(Eva l("Status")) + "'>"%>
</ItemTemplate>
</asp:TemplateCol umn>

....
protected string GetImage(object n)
{
if (n != DBNull.Value) {
if ((string)n == "paid") {
return ("/images/green_circle.jp g" );
}
....
else
return ("");
}

Another way is to name icon files in the same way as you named the
values of the "status" field. Say, you have status = 0 (past due), 1
(paid), 2 (isn't past due) then you can name your files as
circle_0.jpg, circle_1.jpg, circle_2.jpg and then you would not neet
any codebehind method

<asp:TemplateCo lumn>
<ItemTemplate >
<%#"<img src='/images/status_" + Eval("Status") + ".jpg'>"%>
</ItemTemplate>
</asp:TemplateCol umn>

Sep 5 '07 #10

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

Similar topics

3
2981
by: Guadala Harry | last post by:
Here's the functionality I'm after: I need for a page to display a photo. When users click on other links within the page, the photo changes. I'd like to swap out the photo without doing a Postback of the entire page. I initially implemented this with an aspx page that contains an IFame which displays only the picture (gif). The behavior was what I wanted, but the problem is that the IFrame does not resize with the photo......
3
2361
by: CLEAR-RCIC | last post by:
I have several images i want to display in an ASP.Net application. The images are being passed to me in binary format from another application. Is there a good way to write them directly to an HMTL page without having to save them to the server and create a URL to the virtual directory? FYI: I currently am doing this with just single images. I do a Response.BinaryWrite(byte) to display the one image. The advantage is that I never...
3
2516
by: velu | last post by:
Asp.Net 2 I am trying to display Image from Northwind Database. I ran a queary "SELECT CategoryID, CategoryName, Description, Picture FROM Categories" but the Dataview displayes all the fields except Picture. so i add a Imagefield to display images..but now i get cross icon.. below is the code. correct me where i am wrong....
1
6751
by: VMI | last post by:
I'm working on an ecommerce-type we app, and I would like to save/retrieve image information into my sql server DB. If I save the file path in my table, how can I use that info to display the image in the gridview? IS there a better way? Since there are so many products, I don't want to save the actual image into the DB. I just want to save some info that I can later reference when I fill up my grid. What's the best way to do this? ...
1
4744
by: spitapps | last post by:
I have a gridview declaratively added to my webform. This gridview displays data from a stored procedure returned as a dataset. Once the dataset has been modified slightly i bind it to my gridview control. Now where and how would i go about adding a column to my gridview dynamically that is a checkboxfield and is checked based on some criteria i want to use. An example... if...
0
1301
by: gomzi | last post by:
Hi, I have some images which I want to display in a gridview. I would like the images to be displayed in a matrix form. i.e. 3 (by 3)on each row. Right now I am not sure as to how I could achieve that. Any help would be appreciated. Thanks, Gomzi.
2
1575
by: Paulo | last post by:
Hi, how are you ? Can you send me any examples about storing images on bd and showing them on gridview? Im using VS2005 asp.net 2.0 C# Thanks a lot!
4
11009
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like to iterate thru the gridview's rows, examine the databound controls, then perform a database action. for some reason, i can't find the controls. i have a two templates: one that uses a label the other uses a textbox to display data. when the...
3
3082
by: anjali5 | last post by:
Hello Everyone, I want to display an image in my gridview. The only thing is my datatabse table is returning true if there is an image and false if there is no image and I am binding my gridview with dataset. This dataset contains a colun called hasAttachments as true or false. Is it possible to display image in the image field? This image does not exsist in the database. I have image in the image folder in my application code. ...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
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
9281
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...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
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...
0
6022
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
4525
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...
1
3238
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 we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.