What's the best practice to achieve this?

G

gnewsgroup

I am not sure how to describe such hanging(?) tables in English
language. But, the following picture shows it clearly.

http://farm3.static.flickr.com/2223/2176441194_37ee1f9ca7_o.png

Normally, it is pretty easy to write a sql that gives us the table
shown at the top of the image. In the web form, we quite often would
like to present it as shown at the bottom of the image.

What's the *easiest* way to do?

I have done this by simply constructing the table through spitting
out

<tr><td>blah blah</td><td>blah blah</td></tr>.

Better yet (not shown in the image), add one additional line for each
customer to display his/her order subtotal.

I guess there might be easier ways to achieve the same result, either
in the database layer or in the application layer.

Any idea?
 
E

Eliyahu Goldin

Use the repeater control. Make the ItemTemplate out of 2 rows:

<tr runat="server" id="trData">
<td>Binding expression for column 1</td>
<td>Binding expression for column 2</td>
<td>Binding expression for column 3</td>
</tr>
<tr runat="server" id="trSubtotal">
<td colspan="3">Subtotal for user <asp:Label runat="server" id="lblUserName"
/> is <asp:Label runat="server" id="lblUserSubtotal" />
</td>
</tr>

Make the HeaderTemplate as <table> and the FooterTemplate as </table>.

Handle the PreRender event to loop through the repeater items to show user
names only in the first trData rows for the same user. That is easily
controllable with the Visible property.

In the same loop detect the last item for every user and make the trSubtotal
row visible. Hide it for all other items. Again, do it with the Visible
property for the row.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
G

gnewsgroup

Use the repeater control. Make the ItemTemplate out of 2 rows:

<tr runat="server" id="trData">
<td>Binding expression for column 1</td>
<td>Binding expression for column 2</td>
<td>Binding expression for column 3</td>
</tr>
<tr runat="server" id="trSubtotal">
<td colspan="3">Subtotal for user <asp:Label runat="server" id="lblUserName"
/> is <asp:Label runat="server" id="lblUserSubtotal" />
</td>
</tr>

Make the HeaderTemplate as <table> and the FooterTemplate as </table>.

Handle the PreRender event to loop through the repeater items to show user
names only in the first trData rows for the same user. That is easily
controllable with the Visible property.

In the same loop detect the last item for every user and make the trSubtotal
row visible. Hide it for all other items. Again, do it with the Visible
property for the row.

Thank you. I thought about Repeater control, too. But I didn't know
how to hide any cell. Now that you say that this can be done through
handling PreRender, I am gonna look into it.

Guess what, I have never handled the PreRender event. Not sure how to
do it.
 

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

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top