0

I'm developing a website. I have an Access database that I pull image names from that i want to use as parameters to post images from my folder using C# code in VS 2010. I want to know how to access the image name as a string and insert it into my asp image element. I'm guessing I need to store the results of my "Select" query in a variable in order to pass it through the "Eval" function, but I'm just guessing and nor have I figured out how to do it.

The following section of code is where I established a connection with the database, used the Datalist control to list the information on my webpage that this code is for. And so what I'm trying to ultimately do is use the file name that's in the database as a parameter to grab the correct image from my files and post it to my web page. See below in code where I say FILENAME GOES HERE????? to see where I need to put my filename for my picture.

<asp:AccessDataSource ID="AccessDataSource2" runat="server" 
     DataFile="~/App_Data/TravelJoansDB.accdb" 
     SelectCommand="SELECT * FROM [Table2]"></asp:AccessDataSource>
     <asp:DataList ID="DataList1" DataSourceID="AccessDataSource2" 
             ItemStyle-VerticalAlign="Middle" runat="server" DataKeyField="ID">
         <ItemStyle VerticalAlign="Middle"></ItemStyle>
         <ItemTemplate> 
                ID:
                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
                <br />
                Image:
                <asp:Image ID="Image1" runat="server" ImageUrl='<%# "PlaceImages/" Eval(*FILENAME GOES HERE?????*) %>' />
                <br />
                <br />
         </ItemTemplate>
            </asp:DataList>

1 Answer 1

1

try this

<asp:Image ID="Image2" runat="server" ImageUrl='<%# "PlaceImages/" + Eval("Your_ImageName_Column")%>' />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.