I have a Group table and an Images table in an SQL Server database. Each image is linked to a different Group when they are inserted into the table.

I am trying to display a separate photo gallery for each row in the Group table.

The below Repeater creates a DataList based on the number of rows in the Groups table. However, it displays all images rather than those which are linked to that specific group.

 <asp:Repeater ID="rptGroupGallery" runat="server" EnableViewState="false">
                                                <asp:DataList DataKeyField="ID" RepeatDirection="Horizontal" RepeatColumns="3" CellPadding="5" runat="server" DataSourceID="dataSource">
                                                        <div style="padding-bottom: 10px;">
                                                            <a id="imageLink" href='<%# Eval("filename","~/SlideImages/{0}") %>' title='<%#Eval("imageDesc") %>' rel="lightbox[Brussels]" runat="server">
                                                                <asp:Image ID="Image1" ImageUrl='<%# Bind("filename", "~/SlideImages/{0}") %>' runat="server" Width="112" Height="84" />
                                        <asp:SqlDataSource ID="dataSource" runat="server" ConnectionString="<%$ ConnectionStrings:BallinoraDBConnectionString1 %>" SelectCommand="SELECT * FROM [SlideShowTable]"></asp:SqlDataSource>

C# code below:

 SqlConnection connR;
    string connectionStringR = ConfigurationManager.ConnectionStrings[
    connR = new SqlConnection(connectionStringR);
    SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Groups", connR);
    DataTable dt = new DataTable();
    rptGroupGallery.DataSource = dt;

Below is a sketch of what I would like: sketch

Group SQL:

CREATE TABLE [dbo].[Groups] (
[Group_Id]   INT             IDENTITY (1, 1) NOT NULL,
[Group_Name] NVARCHAR (50)   NULL,
[Group_Desc] NVARCHAR (1000) NULL,


Slideshow SQL:

CREATE TABLE [dbo].[SlideShowTable] (
[ID]        INT           IDENTITY (1, 1) NOT NULL,
[filename]  VARCHAR (250) NULL,
[imageDesc] VARCHAR (250) NULL,
[groupNo]   INT           NULL);

Also, sample data: smpleData


Here are the table structures I am working with:



Below is the output when I have 5 rows in the Group table, and 3 images in the Images table, all with different Group_ID's.

screenShot I understand the SqlDataSource's Select Command is "SELECT * FROM tableName".

To seperate the groups, I know that I will need to add a parameter to this command (to pass the various ID's from the Group table).

But I'm not sure how to add that within the repeater so that it counts the number of rows.

Can anyone tell me how to go about this?

Related posts

Recent Viewed