Question about Image Column in gridview Fw2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm fairly new to this so bear with me!

I have created a gridview in an aspx page which successfully talks to a SQL
backend via a datasource. One of the colums contains a reference to an image
which I display as a column in the grid. This works.

My question is this. Can I make the image into a hyperlink so that when I
click on the image it effectively causes a hyperlink equivalent to the
example below.

TIA

Dave

<A href=""anotherpage.aspx?ID=n"><img etc...></a>

Where n=the identity value of the ID column.
 
<asp:HyperLinkField DataNavigateUrlFields="ID_FieldName"
DataNavigateUrlFormatString="anotherpage.aspx?id={0}"
Text ="<img src='MyImage.gif'/>" />
 
Phillip Williams said:
<asp:HyperLinkField DataNavigateUrlFields="ID_FieldName"
DataNavigateUrlFormatString="anotherpage.aspx?id={0}"
Text ="<img src='MyImage.gif'/>" />

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

Thanks Philip, that kind of helped but the actual file name of the img is
variable and is held in one of the fields in the row.

For example, the source may contain the following fields

ID int identity etc,
Text Field varchar(50),
ImgName varchar(50) , /*E.g.,'iconname.gif' */
OtherFields

How can I make gridview column use the ImgName as the source file name for
the image?

TIA,

Dave
 
Hi Dave,

You can use the DataTextField property to get the image name from the data
like this:

<asp:HyperLinkField DataNavigateUrlFields="ID_FieldName"
DataNavigateUrlFormatString="anotherpage.aspx?id={0}"
DataTextField="ImgName" DataTextFieldFormatString="<img src='{0}'/>"/>
 
Back
Top