Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have image tag and i want such condition operator that show NOImage.gif if image is not available for product
XML
<img src='<%#"../pImage/thumb/"+ Eval("ProductImage")? %>' alt='<%#Eval("ProductName") %>' runat="server" />


I have done it before. It was like following.

HTML
<img src='<%#"images/thumbnails/"+Eval("ProductImage")==""?"images/thumbnails/xyz.jpg":"images/thumbnails/"+Eval("ProductImage")"%'> />
Posted
Updated 31-Aug-12 20:27pm
v4

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
 
Share this answer
 
v2
Comments
ravi sharma11 1-Sep-12 2:34am    
I have noimage.jpeg in database. I have update question please check
AmitGajjar 1-Sep-12 2:37am    
is ProductImage is property ? is it's value coming from database ?
AmitGajjar 1-Sep-12 2:39am    
And even you also have done correctly. Check if Eval("ProductImage") returns empty ?
ravi sharma11 1-Sep-12 3:03am    
Yes ProductImage is a field in database. I want o make such code as if database Productimage field is empty then show noimage.jpeg
AmitGajjar 1-Sep-12 3:18am    
You can also do that in RowDataBound event.
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
XML
<%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:
XML
ImageUrl=<%#Eval("iPath")%>

and then on the code begin it would be something like:
XML
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
 
Share this answer
 
v2
Comments
ravi sharma11 31-Aug-12 12:41pm    
But I have binded it in follwing way so I just want to keep condition in Datalist
public void BindProduct()
{
rptProduct.DataSource = objProduct.SelectHomePageProduct();
rptProduct.DataBind();
}

And I dont want to code too much. It's really easy, I have done in past but I can not get it because I have done in previouse company..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900