Skip to main content

How to: Dynamically Change Images Displayed Within Data Cells

This example demonstrates how to dynamically change images displayed in the Change column’s cells.

For the full example, see the following demo: Grid - Live Data.

The image below shows the result:


protected string GetIconImageUrl(GridViewDataItemTemplateContainer container) {
     Quote quote = (Quote)grid.GetRow(container.VisibleIndex);
     return String.Format("Images/{0}.gif", quote.Change >= 0 ? "Up" : "Down");

protected string GetPercentageText(GridViewDataItemTemplateContainer container) {
     Quote quote = (Quote)grid.GetRow(container.VisibleIndex);
     return HttpUtility.HtmlEncode(quote.Change.ToString("P"));