Mr A
Mr A

Reputation: 6768

How to set a location for alternative text in <asp:image button>

<asp:ImageButton ID="ImageButton2" runat="server" Width="100px"
    AlternateText='<%# Eval("Img_Id")%>' Height="100px"/>

In the AlternateText='<%# Eval("Img_Id")%>' I have to write something like this: '~/images/<%# Eval("Img_Id")%>'

Upvotes: 0

Views: 1189

Answers (2)

Kelsey
Kelsey

Reputation: 47726

You can just do the following:

<asp:ImageButton ID="ImageButton2" runat="server" Width="100px" Height="100px"
     AlternateText='<%# this.ResolveUrl("~/images/" + Eval("Img_Id")) %>'/> 

Here is a link to some information that will explain url and paths resolving.

EDIT: as per my comment, I think you are not using the correct property set the following property to display the image. Your orignal question just looked like you were trying to set the AlternateText property which will not do anything for the image:

 ImageUrl='<%# this.ResolveUrl("~/images/" + Eval("Img_Id")) %>'

Upvotes: 2

Kent
Kent

Reputation: 2960

<asp:ImageButton ID="ImageButton2" runat="server" Width="100px"
    AlternateText='<%# "~/images/" + Eval("Img_Id").toString()%>' Height="100px"/>

^^

Upvotes: 1

Related Questions