在gridview中动态显示图像 [英] Dynamically displaying images in a gridview

查看:51
本文介绍了在gridview中动态显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经google了并尝试了各种方法,但无法解决这个问题。\\ b
问题。 MSDN上的文章:在GridView列中显示图像

只显示一个简单的情况,其中gridview的所有数据(包括图像)来自单个表/数据源。


这是我的情况。在我的网络应用程序中,我需要在gridview中显示

客户账单信息。


客户名称和联系信息来自Customer表。


如果客户的账单已过期,我会在该行的最后一个
中显示一个红色圆圈。

如果客户的账单已经支付,我在该行的最后一栏

中显示一个绿色圆圈。

如果客户的账单不是到期时,我在该行的最后一栏

中显示一个蓝色圆圈。


简单,对吧?


这些小彩色圆圈可以来自数据库表格或来自

ArrayList。


我在最后一栏中尝试过模板字段然后将图像控件的

ImageUrl绑定到我在代码隐藏中的方法,

如下:


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


它没有不工作。


我删除了Image控件,只是尝试了:


< img src =''GetIconPath()''/> ;


它仍然无效。


然后,我尝试使用Label控件并在后面的代码中我说


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


它仍然无法正常工作。


然后,我创建了另一个页面GetIconPath.aspx,它简单地输出

图标的路径为字符串,如〜/ Images / red_cirlce.jpg,以及

在图像中控制,我说


< asp:Image .... ImageUrl =" GetIconPath.aspx" ...>< / asp:图片>


它仍然拒绝工作。


我试过< asp:ImageFieldinstead of < asp:TemplateField>,它仍然是

拒绝工作。我已经花了一整天的时间来处理这个问题,并且无法解决这个问题。


任何提示都非常受欢迎。

解决方案

< gn ******** @ gmail.comwrote in message

news:11 *** *******************@57g2000hsv.googlegro ups.com ...


任何提示都非常感谢。



当这样的事情发生时,我首先想到的是相对路径...


你是否*绝对确定*那个各种图像文件的路径是

正确...?


请记住< asp:Imagewebcontrol的ImageUrl属性是

期望指向图形的相对或绝对URL,例如jpg,bmp,

gif等:
http://msdn2.microsoft.com/en-us/lib...rl(vs80).aspx


当您执行查看源代码并检查HTML时,是否会对

内容产生影响......?

-

Mark Rae

ASP.NET MVP
http://www.markrae.net




如果是我,我'在gridview的onRowBound处理程序中执行此操作 -

将允许您访问该行的数据。从那以后你就可以发现支付/延迟/不迟到的状态以及直接将src放入

图像标签的机会。


john


< gn ******** @ gmail.comwrote in message

news:11 ***** *****************@57g2000hsv.googlegro ups.com ...


我用google搜索并尝试过各种方法,但无法解决这个问题。 MSDN上的文章:在GridView列中显示图像

只显示一个简单的情况,其中gridview的所有数据(包括图像)来自单个表/数据源。


这是我的情况。在我的网络应用程序中,我需要在gridview中显示

客户账单信息。


客户名称和联系信息来自Customer表。


如果客户的账单已过期,我会在该行的最后一个
中显示一个红色圆圈。

如果客户的账单已经支付,我在该行的最后一栏

中显示一个绿色圆圈。

如果客户的账单不是到期时,我在该行的最后一栏

中显示一个蓝色圆圈。


简单,对吧?


这些小彩色圆圈可以来自数据库表格或来自

ArrayList。


我在最后一栏中尝试过模板字段然后将图像控件的

ImageUrl绑定到我在代码隐藏中的方法,

如下:


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


它没有k。


我删除了Image控件并尝试了:


< img src =''GetIconPath()''/>


它仍然无法正常工作。


然后,我尝试使用Label控件并在后面的代码中我说


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


它仍然无法正常工作。


然后,我创建了另一个页面GetIconPath.aspx,它简单地输出

图标的路径为字符串,如〜/ Images / red_cirlce.jpg,以及

在图像中控制,我说


< asp:Image .... ImageUrl =" GetIconPath.aspx" ...>< / asp:图片>


它仍然拒绝工作。


我试过< asp:ImageFieldinstead of < asp:TemplateField>,它仍然是

拒绝工作。我已经花了一整天的时间来处理这个问题,并且无法解决这个问题。


任何提示都非常受欢迎。



9月4日晚上10点54分,gnewsgr ... @ gmail.com写道:


我已经google了并尝试了各种方法,但无法解决这个问题。 MSDN上的文章:在GridView列中显示图像

只显示一个简单的情况,其中gridview的所有数据(包括图像)来自单个表/数据源。


这是我的情况。在我的网络应用程序中,我需要在gridview中显示

客户账单信息。


客户名称和联系信息来自Customer表。


如果客户的账单已过期,我会在该行的最后一个
中显示一个红色圆圈。

如果客户的账单已经支付,我在该行的最后一栏

中显示一个绿色圆圈。

如果客户的账单不是到期时,我在该行的最后一栏

中显示一个蓝色圆圈。


简单,对吧?


这些小彩色圆圈可以来自数据库表格或来自

ArrayList。


我在最后一栏中尝试过模板字段然后将图像控件的

ImageUrl绑定到我在代码隐藏中的方法,

如下:


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


它没有k。


我删除了Image控件并尝试了:


< img src =''GetIconPath()''/>


它仍然无法正常工作。


然后,我尝试使用Label控件并在后面的代码中我说


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


它仍然无法正常工作。


然后,我创建了另一个页面GetIconPath.aspx,它简单地输出

图标的路径为字符串,如〜/ Images / red_cirlce.jpg,以及

在图像中控制,我说


< asp:Image .... ImageUrl =" GetIconPath.aspx" ...>< / asp:图片>


它仍然拒绝工作。


我试过< asp:ImageFieldinstead of < asp:TemplateField>,它仍然是

拒绝工作。我已经花了一整天的时间来处理这个问题,并且无法解决这个问题。


任何提示都非常受欢迎。



例如


< asp:TemplateColumn>

< ItemTemplate>

<%#"< img src =''" + GetIconPath()+"''>"%>

< / ItemTemplate>

< / asp:TemplateColumn>


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=''GetIconPath()'' />

And it still did not work.

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

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

It still didn''t work.

Then, I created another page GetIconPath.aspx, 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="GetIconPath.aspx" ... ></asp:Image>

It still refuses to work.

I tried <asp:ImageFieldinstead of <asp:TemplateField>, 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.

解决方案

<gn********@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.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:Imagewebcontrol 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



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********@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.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=''GetIconPath()'' />

And it still did not work.

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

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

It still didn''t work.

Then, I created another page GetIconPath.aspx, 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="GetIconPath.aspx" ... ></asp:Image>

It still refuses to work.

I tried <asp:ImageFieldinstead of <asp:TemplateField>, 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.



On Sep 4, 10:54 pm, gnewsgr...@gmail.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=''GetIconPath()'' />

And it still did not work.

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

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

It still didn''t work.

Then, I created another page GetIconPath.aspx, 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="GetIconPath.aspx" ... ></asp:Image>

It still refuses to work.

I tried <asp:ImageFieldinstead of <asp:TemplateField>, 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:TemplateColumn>
<ItemTemplate>
<%#"<img src=''" + GetIconPath() + "''>"%>
</ItemTemplate>
</asp:TemplateColumn>


这篇关于在gridview中动态显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆