Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid

Status
Not open for further replies.

fmardani

Programmer
Jul 24, 2003
152
Hi,
In a datagrid on the web form using C#, I would like to have a column which retrieves a picture based on the GetImage function that I have created and then I would like this to be a hyperlink so that when you click it it uses the value of the first column.
This is what I have using itemtemplate. It retrieves the image but I do not know how to make this image into a hyperlink.
Thanks

<asp:TemplateColumn HeaderText="US">
<ItemTemplate>
<asp:Image Runat="server" ImageUrl='<%# GetImage(DataBinder.Eval(Container,"DataItem.Status").ToString()) %>'></asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
 
I suggest just using regularly flavored HTML controls for this type of application:

<a href='<%# //Your other databinding statement here %>'>
<img src='<%# GetImage(DataBinder.Eval(Container,"DataItem.Status").ToString()) %>' />
</a>

Also, try not to use latebinding syntax (DataBinder.Eval). Instead, downcast your dataitem, and reference it like so (assuming DataTable as the datasource):

GetImage(((DataRowView)Container.DataItem)["Status"])

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top