Use alternate image field

Posted on 2010-01-11
Medium Priority
Last Modified: 2012-05-08
I have created a small function to return an alternate image if the origional image field is empty as per the code below:

ImageUrl='<%# FixNullBind(Eval("PTProductImage")) %>'

Public Function FixNullBind(ByVal sItem As Object) As String
        If IsDBNull(sItem) Then
            '    Return ("/images/logo.jpg")
            Return ("<%# Bind(" + "" + "GFImageURL" + "" + ")%>")
            Return CStr(sItem)
        End If
    End Function

This works fine if I populate the return with the hardcoded image location, however I would like to use an image ("GFImageURL") in the same table that will always be populate even if the original ("PTProductImage")  isn't. In debugging I can  look at the return and it is poulated with
<%# Bind("GFImageURL")%> as I had planned but this is not being translated to the record withing this field.
Assistance most welcome.
Question by:Simon Cripps
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 13

Expert Comment

ID: 26288685
Return("<%# Bind(" + GFImageURL +")%>")

Open in new window


Author Comment

by:Simon Cripps
ID: 26289024
I tried that origonally but it did not like GFImageURL as it was not declared.
I stuck with your solution and inserted
Dim GFImageURL As String
GFImageURL = "GFImageURL"
above. This again sets <%# Bind(GFImageURL)%> in the return but this is not interpreted in the ImageURL property.
 I thought it may just be missing quote marks arround GFImageURL. So recoded it as:
Return ("<%# Bind(" + Chr(34) + "GFImageURL" + Chr(34) + ") %>") which passed back the quotes but still did not give any value.  <%# Bind("GFImageURL")%>
 I have checked to ensure that GFImageURL is a field within the form and same table as PTProductImage.
LVL 13

Expert Comment

ID: 26289132
where do you read the GFImageURL from ?

Author Comment

by:Simon Cripps
ID: 26293098
Below Is a cut down version of the page source to show the structure of the page. I have tried moving the SQLDatasource4 to next to SQLDatasource3 at the top of the page , however I get an error "Object reference not set to an instance of an object." in return on the repeater Item databound sub. This sub code is shown after the page source code below. The reference error source occours on line
ds.SelectParameters("PPTProductID").DefaultValue = pptProductID.ToString(). I don't know if this is the correct way to go, If you could look at this it would be great.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
       <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:acVitaConnectionString %>"

                <asp:SessionParameter ConvertEmptyStringToNull="false" DefaultValue="" Name="Brand" SessionField="SessionBrand" />
                <asp:SessionParameter ConvertEmptyStringToNull="false" DefaultValue="0" Name="MinPrice" SessionField="SessionMinPrice" />
                <asp:SessionParameter ConvertEmptyStringToNull="false" DefaultValue="160" Name="MaxPrice" SessionField="SessionMaxPrice" />
<div class="DivPageBody">        
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource3" OnItemDataBound="Repeater1_ItemDataBound">
  <asp:FormView DefaultMode="ReadOnly" ID="FormView4" runat="server" DataSourceID="SqlDataSource4" DataKeyNames="PPTProductID">
<div class="itemoffer" > 
<asp:Table ID="Table3" runat="server" Width="800px" Height="100px" >
<asp:TableRow Width="800px" >
<asp:TableCell Width="100px"> <asp:Image ID="ImageFile" runat="server" ImageUrl='<%# FixNullBind(Eval("PPTProductImage")) %>' Height="100px" Width="100px"  />
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:acVitaConnectionString %>" 
        SelectCommand="SELECT TOP (5) ProductTable.PPTProductID, ProductTable.PPTProductImage, GlobalFeed.GFImageURL, rest of SQL here">
<asp:SessionParameter Name="Brand" ConvertEmptyStringToNull="false" DefaultValue="" essionField="SessionBrand" />

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim row As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
Dim pptProductID As Integer = CInt(row.Row("PPTProductID"))
Dim fv As FormView = DirectCast(e.Item.FindControl("FormView4"), FormView)
Dim ds As New SqlDataSource
ds = DirectCast(e.Item.FindControl("SqlDataSource4"), SqlDataSource)
Dim ds1 As New SqlDataSource
ds1 = DirectCast(e.Item.FindControl("SqlDataSource3"), SqlDataSource)
ds.SelectParameters("PPTProductID").DefaultValue = pptProductID.ToString()
End If
End Sub

Open in new window


Accepted Solution

Simon Cripps earned 0 total points
ID: 26312546
Solution found

ImageUrl='<%# FixNullBind(Eval("PTProductImage")Eval("GFImageURL"))  %>'

Public Function FixNullBind(ByVal sItem As Object, ByVal sDefault As Object) As String
        If IsDBNull(sItem) Then
                    Return (sDefault )
                End If
    End Function

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question