0

我正在使用数据列表来显示产品详细信息。这次我想显示图像,但是当图像文件具有图像路径时它会显示,否则它是空的。我想在字段为空时显示虚拟图像..

这是我的代码:

<asp:DataList ID="DataList1" CaptionAlign="Right" runat="server" Width="100%" Visible="true" >
<ItemTemplate>
    <table width="100%" border="0" cellspacing="5" cellpadding="0">
        <tr>
            <td width="2%">
                &nbsp;
            </td>
            <td>
                <div class="Curved_box">
                    <div class="curved_Top">
                        <div class="curved_TopLft">
                        </div>
                        <div class="curved_TopRft">
                        </div>
                    </div>
                    <div class="CurvedContent">
                        <a href="#">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width: 14px; height: 65px;">
                                    </td>
                                    <td style="width: 113px; height: 65px;">
                                        <asp:Image ID="Image1" Style="border: solid 1px #eaeaea; background: " runat="server"
                                            Height="60px" Width="60px" ImageUrl='<%#Bind("fldpic") %>' />
                                    </td>
                                    <td width="80%" align="right" style="height: 65px">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td colspan="2" style="height: 20px" align="left">
                                                    <asp:Label ID="lbl_name" runat="server" Font-Bold="true" Text='<%#Bind("name") %>'></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="width: 247px; height: 20px;" align="left">
                                                    <asp:Label ID="lblProd_Keywd" runat="server" Text='<%# Bind("Desig") %>' Font-Bold="True"></asp:Label>
                                                    &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                                </td>
                                                <td align="left" style="height: 20px">
                                                    <asp:Label ID="lblProd_Code" runat="server" Text='<%# Bind("fldempid") %>'
                                                        Font-Bold="True"></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>

                                            </tr>
                                        </table>

                                    </td>
                                </tr>
                            </table>
                        </a>
                    </div>
                    <div class="curved_Btm">
                        <div class="curved_BtmLft">
                        </div>
                        <div class="curved_BtmRft">
                        </div>
                    </div>
                </div>
            </td>
            <td width="2%">
                &nbsp;
            </td>
        </tr>
    </table>
</ItemTemplate>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" HorizontalAlign="Left" ForeColor="White" />
</asp:DataList>
4

1 回答 1

0

在标签 上添加onerror属性,例如<asp:Image>onerror="this.src = 'url of dummy image'"

更改此标记

<asp:Image ID="Image1" Style="border: solid 1px #eaeaea; background: " 
    runat="server" Height="60px" Width="60px" ImageUrl='<%#Bind("fldpic") %>' />

<asp:Image ID="Image1" Style="border: solid 1px #eaeaea; background: " 
    runat="server" Height="60px" Width="60px" ImageUrl='<%#Bind("fldpic") %>' 
    onerror="this.src = 'url of dummy image'" />
于 2012-09-01T09:58:04.607 回答