Patrick Keane
Patrick Keane

Reputation: 663

Can I replace an asp:GridView value with an image?

I have an asp:GridView which includes many BoundField's. One of the fields, called 'status' shows a value of either 1, 2 or 3 (which is got from a column in the database, obviously).

Is there a way I can replace these numbers with images instead?

i.e.

1 = <img src="img1.png" />
2 = <img src="img2.png" />
3 = <img src="img3.png" />

Change Values to Images

Upvotes: 0

Views: 854

Answers (1)

E.J. Brennan
E.J. Brennan

Reputation: 46879

Yes, using a template field you can do something like this:

<asp:TemplateField HeaderText="Image" >
  <ItemTemplate >            
  <asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/images/img" &  Eval("Status") & ".png" %>'
  </ItemTemplate>
</asp:TemplateField>

Upvotes: 1

Related Questions