Create gallery layout with thumbnails using gridview?

Posted on 2008-11-07
Last Modified: 2012-05-05
I would like to know if anyone can help me solve a bit of a problem I have.
(I don't really use gridviews much as they have always confused me for some reason)

I am using LINQ, stored procedures and a gridview control to display a list of images, BUT what I would like to do it display the returned images in 3 or 4 columns by however many rows. I want to be able to add a link to the image to go to another page. I also only want to show the 'ImageFile' field of the returned data and not the other 2 fields (ID, Category) that will be returned, but I do want to use the ID field in the link on the image.

Can this be done in a GridView or am I better off using some other type of control to get the desired result?

Thanks in advance :)
Question by:clearchannel
    LVL 96

    Expert Comment

    by:Bob Learned
    You would need to translate the underlying data source for the GridView into the form that you need, or you can use a DataList, where you can specify the RepeatColumns, RepeatDirection, and RepeatLayout.

    Author Comment

    A datalist sounds more like what I want. I'll give it a go and let you know if it works for me.
    LVL 96

    Accepted Solution


    Simple DataList Demo

    <% @Import Namespace="System.Data" %>
    <% @Import Namespace="System.Data.SqlClient" %>
    <script language="vb" runat="server">
      Sub Page_Load(sender as Object, e as EventArgs)
      End Sub
      Sub BindData()
        '1. Create a connection
        Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
        '2. Create the command object, passing in the SQL string
        Const strSQL as String = "sp_Popularity"
        Dim myCommand as New SqlCommand(strSQL, myConnection)
        'Set the datagrid's datasource to the datareader and databind
        dlPopularFAQs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
      End Sub
    <asp:DataList runat="server" id="dlPopularFAQs" 
                    Width="85%" Border="1"
                    Font-Name="Verdana" CellPadding="4"
                    RepeatColumns="5" >
         <b>Question:</b><br />
         <%# DataBinder.Eval(Container.DataItem, "Description") %>
         <b>Views:</b><br />
         <%# DataBinder.Eval(Container.DataItem, "ViewCount", "{0:#,###}") %>

    Open in new window


    Author Comment

    Can i create the datatreader using LINQ and stored procedures in the same way?
    Just i do not want to use bare sql commands in the page themselves for security reasons and I build my apps to be secure.


    Author Comment

    Ok I have the data list working, how would I show images in the list?
    LVL 96

    Expert Comment

    by:Bob Learned
    This article describes one way:

    A Robust Image Gallery for ASP.NET

    There are plenty of other examples, given the right Google search expression.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now