JPG not working on ASP Image

2020-05-08 06:06发布

I have an Image object in ASP.NET I am assigning an ImageUrl to it but I'm noticing that it does not display a thing when it's a format different from PNG.

In this case, I need it to accept JPG. What can be done?

<table>
    <tr>
        <td>
            <strong>
                Foto
            </strong>

            <br/>
            <asp:Image ID="Image1" runat="server" ToolTip="Foto" Width="320px" Height="240px" ImageUrl='<%# "C:/Images/pictures/" + Eval("picture") %>' />
        </td>

        <td />

        <td>
            <strong>
                Firma
            </strong>

            <br/>
            <asp:Image ID="imgSignature" runat="server" ToolTip="Firma" Width="320px" Height="240px" ImageUrl='<%# "C:/Images/signatures/" + Eval("signature") %>' />
        </td>
    </tr>
</table>

picture = 1.jpg
signarute = 2.png

the first one is not working, the second one does. This is inside a gridview row.

1条回答
forever°为你锁心
2楼-- · 2020-05-08 06:42

You can't use physical file paths for images. You either need to use the absolute path, or more simply, the relative path, like ~/Images/signatures/myImage.jpg:

<asp:Image ID="imgSignature" runat="server" ToolTip="Firma" Width="320px" Height="240px" ImageUrl='<%# "~/Images/signatures/" + Eval("signature") %>' />

Side note, you shouldn't use tables for layout / formatting. Use CSS.

查看更多
登录 后发表回答