I have three tables as follows: table 1 is called Cat1, table 2 is called subcat1 and table three is called itemsTb. I have created relationships like this:
cat1 to subcat1 (one-to-many)
cat1 to itemstb (one-to-many)
subcat1 to itemstb (one-to-many)
I would like to display items in asp.net repeaters like this:
cat 1....
....item 1
....item 2
....item 3
cat 2
subcat 1 .....
.....item 1
.....item 2
.....item 3
cat 3.....
....item 1
....item 2
etc.
The schema of my tables is like this:
Table: cat
columns:
id int
title varchar
table subcat
columns:
id int
catid int
title varchar
table: items
columns
id int
catid int
subcatid int
title varchar
Anyone has any idea how can I display them using asp.net repeaters? Or do I have to structure my tables differently to make it work? Thanks a lot for your help.
All of the ASP.NET databound controls (Repeater, ListView, GridView, etc.) can use declarative data-binding for their DataSource. This isn’t very well documented IMO, but you can do something like:
The specifics of what you need to bind to the
DataSourceproperty depends on what your initial data (the one that rptCategory is bound to).If it’s a
DataSet, then you need to buildDataRelationsand use the name of the appropriateDataRelation.If it’s a C# object, then you’ll want to use the name of a collection property.
EDIT: Specifics on this particular schema follow….
For your schema, you would need 2 nested repeaters – 1 to handle the items and 1 to handle the subcategories (which would have another nested repeater for its items).
Using DataSets, you could do something like (note this is rough code, you’ll need to fill in some of the missing steps):