问题
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