Server control for tabled dataset results?

  • Thread starter Thread starter MU
  • Start date Start date
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
 
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!
 
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
 
Back
Top