locked
Display image in ListView RRS feed

  • Question

  • User1588015780 posted

    Hi,

    Can anyone help me with displaying images in the list view for the records ? My database has an Images table which associates an image with a record based on a ForeignKey and is also containg a column with the url of the image (most images would probably be stored locally in the Images folder of the project therefore the url would probably be something like "~\Images\Img1.gif").

    Thank you!

    PS: I've ran into some samples on the net (like this one from Scott Hunter) but is not working, probably it was built on a older .Net Framework. I am using VS2010 and DD4.

    Wednesday, June 1, 2011 5:39 PM

Answers

  • User-330204900 posted

    Field Templates only work on the current table so if you view the table with the images in then you will see it, you will need to adapt the field template based on the FK field template.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 4:23 AM

All replies

  • User1446927574 posted

    Its easy to achieve. Lets say you have columnName ImageUrl inth database which Contain path of image. Query database and Bind Listview with it. the following code will help you understand how you can show image in Listview.

    <asp:ListView runat="server" ID="ListView1" >
                <LayoutTemplate>
                    <div>
                        <div runat="server" id="itemPlaceHolder">
                        </div>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <img src='<%#Eval("ImageUrl") %>' alt="" />
                </ItemTemplate>
            </asp:ListView>
    

    Let me know if it works.

    Wednesday, June 1, 2011 6:20 PM
  • User1588015780 posted

    I need this functionality to work with DynamicData, probably something like to add an ImageFiled template to display images from a database link.

    Thursday, June 2, 2011 4:15 AM
  • User-330204900 posted

    Hi KOsmix, I have an old field template that works with file system based images Scotts sample only works with images stored in the DB.

    see Dynamic Data: Part 1 - FileImage_Edit FieldTemplate which is in three parts

    Thursday, June 2, 2011 4:34 AM
  • User1588015780 posted

    Looks very good but what I'm trying do is something more easy: to display the image in the List/Details pages. I don't need any edit functions, just to display the image similar to what you do in Part1->Solution 1. Also I don't want to use any radiobutton list just a simple control to display the image from the image url. Is there a quick solution for this? 

    Thank you.

    Thursday, June 2, 2011 5:52 AM
  • User-330204900 posted

    The just use the read only template.

    Thursday, June 2, 2011 7:21 AM
  • User1588015780 posted

    Hi Stephen,

    I've used your project and it's great but I have only one little problem: in the list view I'm seeing a hyperlink (eg: View Logo) probably because it is a foreign key to the table I'm displaying in the list. How can I set to display directly the image in the List? Thank you.

    Thursday, June 2, 2011 12:55 PM
  • User-330204900 posted

    That is correct, you would need to adapt it to get it to work.

    Thursday, June 2, 2011 1:39 PM
  • User1588015780 posted

    I've set the metadata attribute [DisplayColumn("TinyImageUrl")] but it doesn't work.

    Any hint on how can I do this?

    Thursday, June 2, 2011 1:57 PM
  • User-330204900 posted

    Field Templates only work on the current table so if you view the table with the images in then you will see it, you will need to adapt the field template based on the FK field template.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 3, 2011 4:23 AM