具有条件图像src的图像 [英] Image With conditional Image src

查看:127
本文介绍了具有条件图像src的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图像标签,并且我想要这样的条件运算符:如果图像不可用于产品,则显示NOImage.gif

I have image tag and i want such condition operator that show NOImage.gif if image is not available for product

<img src='<%#"../pImage/thumb/"+ Eval("ProductImage")? %>' alt='<%#Eval("ProductName") %>' runat="server" />



我以前做过.就像下面.



I have done it before. It was like following.

<img src='<%#"images/thumbnails/"+Eval("ProductImage")==""?"images/thumbnails/xyz.jpg":"images/thumbnails/"+Eval("ProductImage")"%'> />

推荐答案



从给定的代码中,我可以理解您具有ProductImage ,而ProductName ProductClass的属性.

如果是这样,您可以使用默认值,例如 ProductImage ="NoImage.jpeg" .并且您还应该在指定的文件夹中包含此类图像.

现在,当您不为ProductImage分配任何值时,它将显示默认图像.

希望我回答您的查询
谢谢
-Amit Gajjar
Hi,

From your given code i can understand that you have ProductImage and ProductName is a property of ProductClass.

If so, you can use Default value like ProductImage ="NoImage.jpeg". And you should also have such image in your specified folder.

Now when you are not assigning any value to ProductImage, it will display default image.

Hope i answer your query
Thanks
-Amit Gajjar


如果信息来自数据库,则下面的代码将有所帮助,如果不是,则尝试对其进行处理,看看是否可以解决.
rsNews =选择语句
the below code will help if the information is coming from a database, if not then try playing round with it to see if you can work it out.
rsNews = select statement
<%if isnull(rsNews("News_Image")) then%>
                                            <img src="images/thumbnails/default image.jpg">
                                            <%else %>
                                            <img src="Image_Display.asp?News_Article_ID=<%=rsnews("News_Article_ID")%>" id="news_image2"

                                                alt="LatestNews" border="0" height="70" name="logo_link0" title="Echo_Images"

                                                width="80" align="middle">
                                    </a>
                                    <%end if %>



或者您可以随时尝试:



or you could always try:

ImageUrl=<%#Eval("iPath")%>


然后在代码上开始,就像:


and then on the code begin it would be something like:

Function GetNews() As System.Data.DataSet

        Dim dataSet As New DataSet
        Dim connectionString As String = "server='xxxxxx';Database='xxxxxx';User ID='xxxxxx';Password='xxxx'"
        Dim queryString As String = "SELECT [x], [image], [image_name], [b], [v], [e], [q], [w], [r[t],'' As [iPath],Image_name, (CASE  WHEN Image IS NULL THEN 0 ELSE 1 END)as Image_Exists FROM [tblX] WHERE (([Active] = 1)"

        Using connection As New System.Data.SqlClient.SqlConnection(connectionString)
            Dim adapter As New System.Data.SqlClient.SqlDataAdapter()
            adapter.SelectCommand = New System.Data.SqlClient.SqlCommand( _
                queryString, connection)
            adapter.Fill(dataSet)
            For i As Integer = 0 To dataSet.Tables(0).Rows.Count - 1
                If (dataSet.Tables(0).Rows(i)("iPath") = "") Then
                    Dim imgPath As String = ""
                    imgPath = Request.PhysicalApplicationPath().ToString() + "images\location\" + (dataSet.Tables(0).Rows(i)("Image_name")).ToString()
                    'imgPath = "http://?????\images\location\" + (dataSet.Tables(0).Rows(i)("Image_name")).ToString()
                    If (dataSet.Tables(0).Rows(i)("Image_Exists")).ToString = "1" Then
                        'dataSet.Tables(0).Rows(i)("iPath") = "../images/location/" + (dataSet.Tables(0).Rows(i)("Image_name")).ToString()
                        dataSet.Tables(0).Rows(i)("iPath") = "../Image_Display.asp?News_Article_ID=" + (dataSet.Tables(0).Rows(i)("News_article_id")).ToString()
                    Else
                        dataSet.Tables(0).Rows(i)("iPath") = "../images/location/NOImage.jpg"
                        ' dataSet.Tables(0).Rows(i)("iPath") = "http://?????/images/location/NOImage.jpg"
                    End If
                End If
            Next
            Return dataSet
        End Using


    End Function


这篇关于具有条件图像src的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆