Server control for tabled dataset results?

M

MU

Hello

I would like to take a dataset of Products and their Product photo and
display it on the page in a table format where there are 4 columns and
as many rows as needed. Therefore, if my dataset returned 20
products, there would be 5 rows of 4 columns, ie. 5 rows of Product
pictures.

Any thoughts on what control I should use and roughly how I would go
about doing it?

Thanks so much
MU
 
N

Nathan Sokalski

I would probably use the Repeater control. As for your 4 column situation,
you will probably need to do some manipulation using either the ItemCreated
or ItemDataBound events. My basic suggestion would be to have the template
include the <td></td> tags (and all the stuff between them that display the
product), and use the e.Item.ItemIndex property to determine whether you
need to programmatically insert a <tr> at the beginning of the template, a
</tr> tag at the end of the template, or neither. You will also need to add
code to include any empty <td></td>'s (for example, if you have 18 products
you will need 2 empty <td></td>'s). The reason for all this extra manual
calculation is the fact that you are retrieving your product data with one
product per record, but you want a table with 4 products per row. Good Luck!
 
M

MU

I would probably use the Repeater control. As for your 4 column situation,
you will probably need to do some manipulation using either the ItemCreated
or ItemDataBound events. My basic suggestion would be to have the template
include the <td></td> tags (and all the stuff between them that display the
product), and use the e.Item.ItemIndex property to determine whether you
need to programmatically insert a <tr> at the beginning of the template, a
</tr> tag at the end of the template, or neither. You will also need to add
code to include any empty <td></td>'s (for example, if you have 18 products
you will need 2 empty <td></td>'s). The reason for all this extra manual
calculation is the fact that you are retrieving your product data with one
product per record, but you want a table with 4 products per row. Good Luck!

Worked awesome! I just had a test at the beginning of the
ItemTemplate and after my <TD> tags to test a MOD to see if it was 0
at the beginning or ItemIndex - 1 for the end, if so, I added a <TR>
or </TR>!

Thanks
MU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top