[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

Create gallery layout with thumbnails using gridview?

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 :)
  • 3
  • 3
1 Solution
Bob LearnedCommented:
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.
clearchannelAuthor Commented:
A datalist sounds more like what I want. I'll give it a go and let you know if it works for me.
Bob LearnedCommented:

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

clearchannelAuthor Commented:
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.

clearchannelAuthor Commented:
Ok I have the data list working, how would I show images in the list?
Bob LearnedCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now