Solved

DataList control in ASP.NET not showing images

Posted on 2011-02-17
5
1,178 Views
Last Modified: 2013-12-17
I am working on a photo gallery but the DataList is not showing the images in the folder. It will show the placeholder but not the actual images.
<asp:DataList ID="dlImages" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" Width="100%" CellPadding="2" CellSpacing="0">
        <ItemTemplate>
            <img src='<%# Eval("FullName") %>' width="150" style="border:1px solid gray;" height="250" />
            <hr />
        </ItemTemplate>
        </asp:DataList>

Open in new window

private void LoadDataList()
        {
            
            string imageFolder = MapPath("PostedImages");
            DirectoryInfo objDI = new DirectoryInfo(imageFolder);

            dlImages.DataSource = objDI.GetFiles();
            dlImages.DataBind();
        }

Open in new window

0
Comment
Question by:fishbowlstudios
[X]
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
5 Comments
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
ID: 34923430
meaning they are showing the right path...

post rendered html and show where that page is on your web app, and show us where are the images

0
 
LVL 53

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
ID: 34923438
probably you should use something like this

<img src='images\<%# Eval("Name") %>' width="150" style="border:1px solid gray;" height="250" />

assuming you are getting files list under images folder relative to the running page.... and you should use Name not FullName
0
 

Expert Comment

by:pavan_kumar_kokkiragedda
ID: 34923718
Hi,
I think you need to change the src attribute value to this

src='<%# DataBinder.Eval(Container.DataItem,"FullName") %>'

hope it helps.
0
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 34924085
Hi check following code, so you will get an idea to show Image and other Details



 <asp:DataList ID="dListItems" runat="server" RepeatColumns="4" width="300px"
                    DataKeyField="Image_Id"
                    RepeatDirection="Horizontal" onitemcreated="dListItems_ItemCreated"
                    onitemdatabound="dListItems_ItemDataBound">
                                <ItemTemplate>
                              <!-- box start -->
                              <div class="col-1 new-users">
                                                <li class="prodlistitem" id="listproduct_iPhone_4_12" style="background-image: url('"<%# Eval("Prod_ImagePath") %>"');">

                                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Prod_Id") %>' Visible="false"></asp:Label>
                              <h3><a href="Product_Details.aspx?<%# Eval("Prod_Id") %>" id="listproduct_iPhone_4 1"><%# Eval("Prod_Name") %></a></h3>
                              
                              <a href="Product_Details.aspx?PID=<%# Eval("Prod_Id") %>" class="full-item-click">
                    <asp:Image ID="listproduct_iPhone_4_1" runat="server" Height="110px" ImageUrl='<%# Eval("Prod_ImagePath") %>' data-zoomsrc='<%# Eval("Prod_ImagePath") %>'  Width="110px" />
                   
                    </a>
                    <div class="product-meta">
                                    <div class="price">
                                          <a href="Product_Details.aspx" class="price" id="listproduct_iPhone_4"><%# Eval("Prod_Price_inDoller")%></a>
                           
               
                                <asp:Button ID="Button2" runat="server" Text="Add to Cart" CommandName="image" Visible="false" CommandArgument='<%# Eval("Prod_Id") %>' OnClick="AddToCart" BackColor="#08a5bd" ForeColor="White" />
                            </p>
                           
                            </p>
                                    </div>
                        <div id="ProductRelatedImage">
                            <asp:DataList ID="DataList1" runat="server" DataKeyField="Prod_ImagePath" DataSourceID="SqlDataSource6"
                            RepeatColumns="4" RepeatDirection="Horizontal" Width="40px" Height="40px">
                        <ItemTemplate>
                            <div style="border:1px">
                                <h1><asp:Label ID="Label7" runat="server" Text='<%# Eval("Prod_Name") %>' Visible="false"></asp:Label></h1>
                                <a href="Product_Details.aspx?PID=<%# Eval("Prod_Id") %>"><asp:Image ID="Image7" runat="server" Height="30px"
                                    ImageUrl='<%# Eval("Prod_ImagePath") %>' Width="30px" Visible="false" /></a>
                                    <img alt="" src='<%# Eval("Prod_ImagePath") %>' data-zoomsrc='<%# Eval("Prod_ImagePath") %>' id="myimage" Height="30px" Width="30px" />
                            </div>
                        </ItemTemplate>
                        </asp:DataList>
                        <asp:SqlDataSource ID="SqlDataSource6" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
           
           
       
        SelectCommand="SELECT Product.Prod_Id, Product.Prod_Name, Product.Prod_Price_inDoller, Product_Images.Prod_ImagePath, Category.Cat_Id
                        FROM Category INNER JOIN
                        Product ON Category.Cat_Id = Product.Cat_Id INNER JOIN
                        Product_Images ON Product.Prod_Id = Product_Images.Prod_Id
                        WHERE (Product.Prod_Id = @Prod_Id)">
            <SelectParameters>
             
                <asp:ControlParameter Name="Prod_Id" ControlID="Label1" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
                       
                        </div>                                                            
                                    
                            </div>
                    </li>
                      </div>                      <!-- box end -->
                                </ItemTemplate>
                               
               </asp:DataList>
            </ul>            
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
           
            SelectCommand="SELECT [Prod_ImageId], [Prod_ImagePath], [Prod_Id] FROM [Product_Images]">
        </asp:SqlDataSource>
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 34924549
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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