Link to home
Start Free TrialLog in
Avatar of 123asp
123asp

asked on

How do I use a dropdownlist in asp.net to pull up a jpg or bitmap photo from a file, e.g. c:\images\Photo1.jpg; or the photo can be stored in an SQL table

I want to use a dropdownlist in asp.net to select the name of a Product Photo, e.g. Wheel1 and have this display the photo (jpg or bitmap) of the wheel.  

For testing purposes the images will be in c:\images\Wheel.jpg etc.   These will later be moved to a website folder.  I have read it is easier to do it this way than try to store the actual images in SQL but either way is fine.  I would like to use VB since I use VBA a great deal in Microsoft Access.

I am great with DB's but a novice at asp.net so please keep it simple.  

This is my first time using Experts Exchange.  If this has been asked you are welcome to point me to it.

Thank you,
ASKER CERTIFIED SOLUTION
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beaudetious
beaudetious

Thank you!  I tried to follow your directions and came up with the code below.  You did not mention to create an image, but I used the tool and created one where the photo would show up.  Correct?

Here's the code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Lookup.aspx.vb" Inherits="Lookup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
   
            <asp:DropDownList runat="server" ID="ddltest" AutoPostBack="True">
            <asp:ListItem Value="-1" Text="Please Select"></asp:ListItem>
            <asp:ListItem Value="photo1.jpg">Photo1</asp:ListItem>
            <asp:ListItem Value="photo2.jpg">Photo2</asp:ListItem>
         
        </asp:DropDownList>

     
   
    <asp:Image ID="Image1" runat="server" Height="286px" Width="330px" />

   
   
    </form>
</body>
</html>

____________

The I double-clicked the drop down list and here's the code behind.  I am not sure I referenced the c:\images correctly.    There are 2 photos in that folder:  photo1.jpg    and photo2.jpg  


Partial Class Lookup
    Inherits System.Web.UI.Page

    Protected Sub ddltest_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddltest.SelectedIndexChanged
        Image1.ImageUrl = "c:\Images\ddltest.SelectedValue" ' SET YOUR PATH TO IMAGE HERE i.e "images/pic1.jpg"
    End Sub
End Class

________________________________

When you "View in Browser" the dropdownlist works and seems to do a post back, but nothing shows up in the image box on the screen.  The image box has the small icon in the upper left as though it cannot find anything.  

If you can correct any mistakes, I will copy and paste what you send.  Thank you,



Confused:  I am a first time user.  I sent a reply to  sm394   and it ended up on the screen for   beaudetious?   Does this matter?
>>>Confused:  I am a first time user.  I sent a reply to  sm394   and it ended up on the screen for   beaudetious?
I am confused too. How did you send the reply? There is no such feature at EE.
By "I sent a reply" I meant that I typed the reply into the Comment section as I am doing here and then clicked Submit.  

To go back to the original code question.  When I select Photo1 from the dropdownlist and then right-click on the Image box on the screen I can see the text "Photo1" but no picture is displayed.

I tried variations on            Image1.ImageUrl = "c:\Images\ddltest.SelectedValue" such as        Image1.ImageUrl = "c:\Images\" & ddltest.SelectedValue  but no luck.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 123asp

ASKER

To:   sm394     and    prairiedog
I worked with the code and ideas you both sent and finally have something that shows the idea is do-able.

Both of you helped me get to this point.  Is there a way I can split the points or what's the next step?
Thanks,