Display DataSet in <table>

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a dataset that contains product data in the following format:

ProdID ProdName Price
1 Laptop $2000
2 Mouse $30
3 Webcam $100
4 DVD-RW $2

Instead of having the entries just displayed in rows in a DataGrid, I'd like
to arrange them in a table of 3 columns like this:

<table>
<tr>
<td>Laptop<br>$2000</td>
<td>Mouse<br>$30</td>
<td>Webcam<br>$100</td>
</tr>
<tr>
<td>DVD-RW<br>$2</td>
<td> </td>
<td> </td>
</tr>
</table>

How can I do this with the Data Controls? How can I make sure that the empty
cells in the last row are still created?


WB.
 
Witha repeater, you can have "any" HTML repeat. The problem, however, is
your line terminating length (3 columns per line, regardless of data
returned). This means either running a repeater and overloading the
OnDataBind method to end table cells or writing a custom control.

A custom control would likely be better. you can create a class that
inherits from WebControl and override the binding method to create the text
output. You then override the Render method to output the text created from
binding. This is the most flexible.

The easiest is in between. Create a user control that outputs from the
CodeBehind. You will use the same methodology as the custom control (ie, make
it a black box).

If this does not make much sense, consider reading the MSDN documentation
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformscontrolshierarchy.asp

or getting a book like
http://www.microsoft.com/MSPress/books/5728.asp

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Hi Cowboy,

Thanks for your reply. However, can you be more specific or direct me to
some code samples? I don't really understand what you meant by "overloading
the
OnDataBind method" or "override the Render method".

I think the way that I'd like to layout my products is quite standard; I'm
surprise that the coding doesn't seem to be as straight forward as I
expected...


WB.
 
Back
Top