Adding image to gridview row dynamically

倾然丶 夕夏残阳落幕 提交于 2019-12-13 04:44:10

问题


In gridview we have 4 columns

Asset Type , Asset Name , Asset Description , Icon

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...

Need Help !!!

Thanks


回答1:


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>

Some Reading:

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

Conditional output in cell based on row data in Gridview's RowDataBound event

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 
}


来源:https://stackoverflow.com/questions/10284961/adding-image-to-gridview-row-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!