sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Rick's Avatar

LINQ to xml with grouping


Question posted by: Rick (Guest) on August 14th, 2008 01:45 PM
VS 2008 Pro.

I'm writing an html report using LINQ to XML by accesing a datatable that I
filled with data.

the output is currently like this:

<html>
....
<table>
....
<tbody>
<%= From o In dt _
Select <tr>
<td><%= o.Field(Of
String)("Description") %></td>
<td><%= o.Field(Of
Int32)("Itemnum") %></td>
<td><%= o.Field(Of
String)("Name") %></td>
<td style="text-align:
right;"><%= o.Field(Of Int32)("OrderCount").ToString("N0") %></td>
<td style="text-align:
right;"><%= o.Field(Of Int64)("PacketTotal").ToString("N0") %></td>
<td style="text-align:
right;"><%= o.Field(Of Decimal)("TotalSold").ToString("N2") %></td>
</tr%>
</tbody>
</table>
</html>

I want to insert a new row <tr><td>... each time the field "Description"
changes and subtotal the "OrderCount", "Packettotal" and "TotalSold" fields.

I can't seem to find anything on Google, but it's probably just because I
don't know the proper question.

Can someone offer a sample or point me to some instructions?

Thanks,

Rick

3 Answers Posted
Martin Honnen's Avatar
Guest - n/a Posts
#2: Re: LINQ to xml with grouping

Rick wrote:
Quote:
Originally Posted by
I want to insert a new row <tr><td>... each time the field "Description"
changes and subtotal the "OrderCount", "Packettotal" and "TotalSold"
fields.
>
I can't seem to find anything on Google, but it's probably just because
I don't know the proper question.


The VB.NET LINQ grouping construct is documented online here:
http://msdn.microsoft.com/en-us/library/bb531412.aspx


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Martin Honnen's Avatar
Guest - n/a Posts
#3: Re: LINQ to xml with grouping

Rick wrote:
Quote:
Originally Posted by
Your output is not valid html.
>
the general structure should be
<table>
<thead>...</thead>
<tbody><tr><td>...</td></tr><tr>...</tr><tr>...</tr></tbody>
</table>
>
All of the <trtags are located inside one <tbody>.


Sorry, that is not true, HTML tables allow several tbody elements, see
http://www.w3.org/TR/html4/struct/tables.html#h-11.2.1, it says
<!ELEMENT TABLE - -
(CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>
so you can have several tbody elements.




--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Rick's Avatar
Guest - n/a Posts
#4: Re: LINQ to xml with grouping

Thanks for pointing that out about multiple <tbodytags inside a table. I
don't do many html reports, but on occasion they are quick and convenient as
a reporting tool, especially now with LINQ.

Rick

"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:%239722cs$IHA.4684@TK2MSFTNGP06.phx.gbl...
Quote:
Originally Posted by
Rick wrote:
>
Quote:
Originally Posted by
>Your output is not valid html.
>>
>the general structure should be
><table>
> <thead>...</thead>
> <tbody><tr><td>...</td></tr><tr>...</tr><tr>...</tr></tbody>
></table>
>>
>All of the <trtags are located inside one <tbody>.

>
Sorry, that is not true, HTML tables allow several tbody elements, see
http://www.w3.org/TR/html4/struct/tables.html#h-11.2.1, it says
<!ELEMENT TABLE - -
(CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>
so you can have several tbody elements.
>
>
>
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


 
Not the answer you were looking for? Post your question . . .
197,022 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,022 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors