开发者

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

开发者 https://www.devze.com 2023-02-18 14:47 出处:网络
<asp:ImageButton ID=\"ImageButton2\" runat=\"server\" Width=\"100px\" AlternateText=\'<%# Eval(\"Img_Id\")%>\' Height=\"100px\"/>
<asp:ImageButton ID="ImageButton2" runat="server" Width="100px"
    AlternateText='<%# Eval("Img_Id")%>' Height="100px"/>

In the AlternateText='<%# Eval("Img_Id")%>' I have to write somethin开发者_如何学JAVAg like this: '~/images/<%# Eval("Img_Id")%>'


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")) %>'


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

^^

0

精彩评论

暂无评论...
验证码 换一张
取 消