Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all!!

I want to show image that i have upload into a folder and fetch the values from database inside a Datalist. The problem that i am facing is that i am able to bound only images to the datalist. how to bind both images and database table at the same time??

i am calling this function on pageload

private void bindDatalist()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath("Thumb"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        dtlistMedia.DataSource = listItems;
        dtlistMedia.DataBind();


this is my .aspx code

XML
<asp:DataList ID="dtlistMedia" runat="server" RepeatColumns="4" CellPadding="6" >
           <ItemTemplate>
            <asp:Image Width="300px" Height="200px" ID="Image1" ImageUrl='<%# Eval("Name", "~/Thumb/{0}") %>' runat="server"  />
            <br />
                     <asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Thumb/{0}") %>' runat="server"/>
          <br />
         <asp:Label runat="server" Text='<%#Eval("Cost") %>'></asp:Label>
           </ItemTemplate>
           <ItemStyle BorderColor="Brown" BorderStyle="dotted" BorderWidth="3px" HorizontalAlign="Center"
VerticalAlign="Bottom" />



the problem is that how to bind the datalist. here i have bound it to listitems but listitem only contains images not the cost which is stored in database.

plz help me out
Posted

You cannot have multiple datasources at a given time for the Datalist. You have to collate the data from directory and database into one and then use that as a datasource.
Retrieve the data separately, merge the data into a third and it should be good to go.
 
Share this answer
 
XML
If your want to show Image from Folder Then store the image in Folder and store image name in database

And use following code to show the image

 <asp:Image Width="300px" Height="200px" ID="Image1" ImageUrl='<%# Eval("ImageName", , "~/ProductImages/{0}" runat="server"  />


EVal("ImageName" is a Column name of Table

And ~/ProductImages is  a folder name in your website
 
Share this answer
 
I want to show image that i have uploaded into a folder and fetch the values from database inside a Datalist. The problem that i am facing is that i am able to bound only images to the datalist. how to bind both images and database table at the same time??


ImageName from database
here image from folder
linkbutton to redirect specific page


i need output this way,,,,


pls help me
 
Share this answer
 
Comments
André Kraak 25-Dec-12 7:32am    
You posted a question as an solution which was probably not want you intended.

If you have a question or comment about the original question use the "Have a Question or Comment?" option beneath the question.
On the other hand if you have a similar problem your best option is to create your own new question, for this use the "Ask a Question" button at the top of the page.

Please move the content of this solution to the appropriate section and remove the solution.

Thank you.
Member 11446311 6-Jul-16 2:55am    
i want to display the image from particulor folder into label in asp.net using database table path
Member 11446311 6-Jul-16 2:55am    
DataTable dt = BAL.Latest_NewsLoadedFor_Updataereg(id);
if (dt.Rows.Count > 0)
{
txtreg.Text = dt.Rows[0]["RegistrationNo"].ToString();
txtApplication.Text = dt.Rows[0]["ApplicationNo"].ToString();

txtName.Text = dt.Rows[0]["Name"].ToString();
txtSurname.Text = dt.Rows[0]["Surname"].ToString();
txtdob.Text = dt.Rows[0]["DOB"].ToString();
txtNationality.Text = dt.Rows[0]["Nationality"].ToString();
txtReligion.Text = dt.Rows[0]["Religion"].ToString();
txtCaste.Text = dt.Rows[0]["Caste"].ToString();
txtAddress.Text = dt.Rows[0]["Address"].ToString();
txtRes.Text = dt.Rows[0]["ResPhone"].ToString();
txtOffice.Text = dt.Rows[0]["officeadd"].ToString();
txtOfPhone.Text = dt.Rows[0]["offphone"].ToString();
txtStatus.Text = dt.Rows[0]["status"].ToString();
Lblimg1.Text = dt.Rows[0]["ImgData"].ToString();
txtRegs.Text = dt.Rows[0]["regstatus"].ToString();
Member 11446311 6-Jul-16 2:56am    
Please can anyone help me
Member 11446311 6-Jul-16 2:57am    
<tr>
<td>
<asp:Label ID="Lblimg1" runat="server" Text="Image1 ">
</td>
<td>

<asp:Image ID="Image1" runat="server" ControlStyle-Width="50" ControlStyle-Height = "50" ImageUrl='<%# Eval("ImgData","~/Images/{0}") %>' />


<%--<asp:Image Width="300px" Height="200px" ID="Image1" ImageUrl='<%# Eval("ImageName", , "~/ProductImages/{0}" runat="server" />

// <%--<asp:Button runat="server" id="UploadButton1" MaxLength="30" Height="25px" Width="300px">--%>

</td>
</tr>

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