all groups > asp.net datagrid control > december 2007 >
You're in the

asp.net datagrid control

group:

Image display and link



Image display and link Angel de la Noche
12/19/2007 3:46:24 PM
asp.net datagrid control: I am working on a desktop application that has a datagrid that is currently
displaying the values from a table, but I need it to display different
images based on the values.
if value = 0 then
show red.gif
elseif value = 50 then
show green.gif
else
show yellow.gif
end if

Next part, the user will click on one of the images. That click will load a
new form, that I will somehow pass the value to.

Can anyone help me figure out how to get the image displayed, and create the
link inside the datagrid that will pass a value to a new form.

I am using Visual Studio 2008.
Re: Image display and link Riki
12/24/2007 4:24:52 PM
[quoted text, click to view]

First of all, change the image column to a template column.
Then use this code:
<ItemTemplate>
<img src='<%# Helper(Eval("myField") %>' alt="status" %>
</ItemTemplate>

The Helper function has to be included in your script block or code behind:

Function Helper(obj As Object) As String
Dim value As Integer=CInt(obj)
if value = 0 then
return "red.gif"
elseif value = 50 then
return "green.gif"
else
return "yellow.gif"
end if
End Function

--
Riki

Re: Image display and link Riki
12/25/2007 8:23:34 PM
Oops, some typos. It should be:

<ItemTemplate>
<img src='<%# Helper(Eval("myField")) %>' alt="status" />
</ItemTemplate>

--
Riki

AddThis Social Bookmark Button