如何在img标签中显示图像?

时间:2013-01-05 06:17:22

标签: c# asp.net web-applications

我想将<input type="image">改为<img>标记。我正在使用嵌套在datalist中的项模板中的ImageButton。

这是我的代码:

    <asp:ImageButton AlternateText=" " onError="imgError(this)" name="imagebtn1" ID="imagebtn1" runat="server" Width="140" Height="140" CommandName="image1" 
CommandArgument="image"  CausesValidation="false" ImageUrl='<%# "GetImage.aspx?sourceCity=" + Eval("City") +"&ID="+ Eval("ID") +"&state="+ Eval("state") %>' OnClick="ImageButton1_Click" PostBackUrl='<%# "details.aspx?sourcecounty=" + Eval("county") +"&fname=" + Eval("col_FirstName") +"&lname=" + Eval("col_LastName") +"&ID="+ Eval("ID") +"&state="+ Eval("state") %>' />

当我使用inspect元素检入Chrome时,我会收到以下代码:

<input type="image" name="ctl00$MainContent$DataList1$ctl42$Image123" id="MainContent_DataList1_Image123_21" onerror="imgError(this)" src="GetImage.aspx?sourceCity=MADISON&amp;ID000113&amp;state=ALABAMA" alt=" " onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$DataList1$ctl42$Image123&quot;, &quot;&quot;, false, &quot;&quot;, &quot;GetImage.aspx?sourceCity=MADISON&amp;ID=000113&amp;state=ALABAMA))" style="height:140px;width:140px;">

1 个答案:

答案 0 :(得分:0)

所以你可以做的是:用<a>标签和<Img>标签替换ImageButton。

<a href='<%# "details.aspx?sourcecounty=" + Eval("county") +"&fname=" + Eval("col_FirstName") +"&lname=" + Eval("col_LastName") +"&ID="+ Eval("ID") +"&state="+ Eval("state") %>'>
    <img id="Image" src='<%# "GetImage.aspx?sourceCity=" + Eval("City") +"&ID="+ Eval("ID") +"&state="+ Eval("state") %>' />
</a>