I have to display photo gallery as show in the image. I store information for photo gallery in 4 different tables. i need to show on main page CategoryName and Albums along with their respected Icon and link them to a AlbumCategoryPage.aspx.
In order to achieve this i am using nested repeater control.
Parent Repeater will show Category Image (as show in red color) and then show Top 4 albums in the same category and so in.
So far i have done it like this
<asp:Repeater ID="rptAlbumCategory" runat="server" OnItemDataBound="rptAlbumCategory_ItemBound">
<ItemTemplate>
<!-- Repeated data -->
<div class="AlbumRowWrapper">
<div id="dAlbumCategory" class="AlbumCategoryIcon">
<asp:Image ID="Image1" ImageUrl='<%# getImagePath(Eval("CategoryImage")) %>' runat="server" />
</div>
</div>
<asp:Repeater ID="rptAlbums" runat="server" >
<ItemTemplate>
<!-- Nested repeated data -->
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Code Behind
On Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ //Get Gallery
DataSet dsAlbumCat = new DataSet();
string strSql = "SELECT * FROM AlbumCategory)";
dsAlbumCat = DataProvider.Connect_Select(strSql);
rptAlbumCategory.DataSource = dsAlbumCat;
rptAlbumCategory.DataBind();
}
}
protected void rptAlbumCategory_ItemBound(Object Sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
Repeater childRepeater = (Repeater)e.Item.FindControl("rptAlbumCategory");
// childRepeater.DataSource = getAlbums();
// childRepeater.DataBind();
}
}
protected void getAlbums()
{
DataSet dsAlbums = new DataSet();
string strSql = "SELECT * FROM AlbumName WHERE CategoryID = " + CategoryID + ")";
dsAlbums = DataProvider.Connect_Select(strSql);
rptAlbums.DataSource = dsAlbums;
rptAlbums.DataBind();
}
protected String getImagePath(object img)
{
string url;
url = "~/Images/gallery/" + img;
return url;
}
With this code i am able to get the following result.
I am not sure how i can pass the CategoryID from the parent repeater to Child repeater so that it will show me the related albums.
I am using nested repeater for first time & find it confusing as i cant find complete example related to my scenario
Table structure
TABLE AlbumCategory
CategoryID
CategoryName
CategoryImageIcon
CategoryVisible
LanguageID
TABLE AlbumName
AlbumID
AlbumName
AlbumDescription
AlbumImageIcon
CategoryID
LanguageID
I would appreciate help in this regard even best approach to accomplish the same design as show in first image
Best Answer
Try this
getCategoriesAndName() will return dataset having two datatables(categories and names). Then on
I think this is easier :-)