Image as a link in Datagrid

G

Guest

Hi!
I have been struggeling for quite some time now with a stupid problem which
drives me crazy.

I have Datagrid, where I load some images from a SQL2000 database. This
works fine, but I am not abel to make the image in the datagrid to be a link
to another page.
I have created a Templeate Column for this.
Could someone be kind enough to point me in the right direction?

This is my template column:

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image id=Image1 Height="60" Width="90" ImageUrl='<%#
DataBinder.Eval(Container.DataItem, "Image") %>' Runat="server" >
</asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
 
V

vMike

SQL_Klovn said:
Hi!
I have been struggeling for quite some time now with a stupid problem which
drives me crazy.

I have Datagrid, where I load some images from a SQL2000 database. This
works fine, but I am not abel to make the image in the datagrid to be a link
to another page.
I have created a Templeate Column for this.
Could someone be kind enough to point me in the right direction?

This is my template column:

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image id=Image1 Height="60" Width="90" ImageUrl='<%#
DataBinder.Eval(Container.DataItem, "Image") %>' Runat="server" >
</asp:Image>
</ItemTemplate>
</asp:TemplateColumn>

One way is to change the image to an asp:hyperlink and provide a navigateurl
value based on the location of the page.
Mike
 
E

Elton Wang

Hi,

One easy way you can do is to assign image's ImageUrl in
datagrid.datagrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType = ListItemType.Item )
{
DataRowView drv = (DataRowView)e.Item.ItemData;
Image image = (Image)e.Item.FindConrol("Image1");
image.ImageUrl = mappingMethod(drv["Image"]); // here
you need to map phsical path to Url
}


HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top