Here is my requirement:
I am creating a 'Local Groups' page, which will display different groups. Each group will have a number of photo albums, and each photo album will contain various images.
I am currently able to display all the images associated with each group, but the Photo Album name / heading above each image is not the correct one (i.e. that image is not connected to that photo album).
The below code displays the following:
These images which are displayed, are linked to the correct groups, 'Red Cross' and 'Gun Club', but those are not the correct Photo Album / Collection names displayed above them.
The correct photo album/collection names should be as follows:
For first pink flower - "red cross first album"
Black photo - "Red cross second Test"
Green photo - "Blarney event"
Final pink flower - "second album"
I feel the issue is in repGroupPhotoGallery_ItemDataBound, but I'm not sure how to fix it. Can anyone please help me? I would really appreciate it. Thanks a lot!
Here is my current code:
- private void BindRepeater()
- {
- string constr = ConfigurationManager.ConnectionStrings["FYPConnectionString1"].ConnectionString;
- using (SqlConnection con = new SqlConnection(constr))
- {
- using (SqlCommand cmd = new SqlCommand())
- {
-
- cmd.CommandText = "select * from Groups WHERE Group_Type ='Group'";
- cmd.Connection = con;
- con.Open();
- repGroupPhotoGallery.DataSource = cmd.ExecuteReader();
- repGroupPhotoGallery.DataBind();
- con.Close();
- }
- }
- }
- protected void repGroupPhotoGallery_ItemDataBound(object sender, RepeaterItemEventArgs e)
- {
- DataList datalist = e.Item.FindControl("dlImages") as DataList;
-
-
- string student_Id = DataBinder.Eval(e.Item.DataItem, "Group_Id").ToString();
- SqlDataAdapter sda = new SqlDataAdapter("select pc_name = pc.Name, s_Id = si.Group_Id, si_filename = si.filename, si_description = si.imageDesc from Groups as s inner join dbo.group_images as si on s.Group_Id = si.group_id inner join dbo.photo_collection_images pci on pci.group_image_id = si.Group_Id inner join dbo.photo_collection as pc on pc.id = pci.photo_collection_id where s.Group_Id =" + student_Id, con);
- DataTable dt = new DataTable();
- sda.Fill(dt);
-
-
- datalist.DataSource = dt;
- datalist.DataBind();
- }
- <asp:Repeater ID="repGroupPhotoGallery" runat="server" OnItemDataBound="repGroupPhotoGallery_ItemDataBound">
- <ItemTemplate>
- <div class="col-md-3">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h3 class="panel-title">
- <%# Eval("Group_Name") %>
- h3>
- div>
-
- <div class="panel-body">
- <div class="col-md-4 text-center">
- <div class="thumbnail">
- <asp:DataList ID="dlImages" runat="server" RepeatDirection="Horizontal" RepeatColumns="3" CellPadding="5">
- <ItemTemplate>
- <div class="caption">
- <h3><%# Eval("pc_name") %><br />h3>
- <a id="imageLink" href='<%# Eval("si_filename","/Group_Images/{0}") %>' title='<%#Eval("si_description") %>' rel="lightbox[Brussels]">
- <asp:Image ID="Image1" ImageUrl='<%# Bind("si_filename", "~/Group_Images/{0}") %>' runat="server" Width="112" Height="84" />
- a>
- div>
- ItemTemplate>
- asp:DataList>
- div>
- div>
- div>
- div>
-
- div>
-
- ItemTemplate>
- asp:Repeater>
Also, here are my SQL tables:
- CREATE TABLE [dbo].[Groups] (
- [Group_Id] INT IDENTITY (1, 1) NOT NULL,
- [Group_Name] NVARCHAR (50) NULL,
- [Group_Desc] NVARCHAR (MAX) NULL,
- [Group_Type] NVARCHAR (50) NULL,
- CONSTRAINT [Groups.Group_Id.PrimaryKey] PRIMARY KEY CLUSTERED ([Group_Id] ASC)
- );
-
- CREATE TABLE [dbo].[Group_Images] (
- [ID] INT IDENTITY (1, 1) NOT NULL,
- [Group_Id] INT NOT NULL,
- [filename] VARCHAR (250) NULL,
- [imageDesc] NVARCHAR (250) NULL,
- CONSTRAINT [Group_Images.ID.Primary Key] PRIMARY KEY CLUSTERED ([ID] ASC),
- CONSTRAINT [Group_Images.to.Groups] FOREIGN KEY ([Group_Id]) REFERENCES [dbo].[Groups] ([Group_Id])
- );
-
- CREATE TABLE [dbo].[Photo_Collection] (
- [Id] INT IDENTITY (1, 1) NOT NULL,
- [Group_Id] INT NOT NULL,
- [Name] NVARCHAR (250) NULL,
- CONSTRAINT [Photo_Collection.Id.PrimaryKey] PRIMARY KEY CLUSTERED ([Id] ASC),
- CONSTRAINT [Photo_Collection.to.Groups] FOREIGN KEY ([Group_Id]) REFERENCES [dbo].[Groups] ([Group_Id])
- );
-
- CREATE TABLE [dbo].[Photo_Collection_Images] (
- [Photo_Collection_Id] INT NOT NULL,
- [Group_Image_Id] INT NOT NULL,
- CONSTRAINT [Photo_Collection_Images.to.Photo_Collection] FOREIGN KEY ([Photo_Collection_Id]) REFERENCES [dbo].[Photo_Collection] ([Id]),
- CONSTRAINT [Photo_Collection_Images.to.Group_Images] FOREIGN KEY ([Group_Image_Id]) REFERENCES [dbo].[Group_Images] ([ID])
- );