动态将图像添加到gridview行 [英] Adding image to gridview row dynamically

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

问题描述

在gridview中,我们有4列

In gridview we have 4 columns

资产类型,资产名称,资产描述,图标

Asset Type , Asset Name , Asset Description , Icon

现在,我们想在图标"列中添加图像,但是根据文档的类型而有所不同.例如.如果资产类型为doc,则将显示Doc图标;如果资产类型为jpg,则将显示Jpg图标

Now We want to add image in Icon column,but will be different depending upon the type of the document. Eg. If asset type is doc then we will display Doc icon;if asset type is jpg then we will display Jpg icon

如何根据资产类型在每行中绑定不同的图像...

How to bind different images in each row depending upon the asset type...

需要帮助!!!

谢谢

推荐答案

我将研究 GridView RowDataBound 方法.访问行 DataItem ,检查类型,然后动态更新图标的ImageUrl(假定您的图标是< asp:Image>

I would look into the GridView RowDataBound method. Access the row DataItem, check for the type, and then either dynamically update the ImageUrl of the icon (presuming that your icon is an <asp:Image>

一些读物:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx

​​基于Gridview的RowDataBound事件中的行数据的单元格中的条件输出

另一种方法是创建一个公共函数,您可以传入资产类型,然后返回图像的URL.

Another way would be to create a public function which you could pass in the asset type, and return the URL of the image.

<asp:Image ImageUrl='<%#GetImageUrl("imageType")%>'

public string GetImageUrl(string imageType){ 
    //return url 
}

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

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