LINQ to xml with grouping

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick

    LINQ to xml with grouping

    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)("Descri ption") %></td>
    <td><%= o.Field(Of
    Int32)("Itemnum ") %></td>
    <td><%= o.Field(Of
    String)("Name") %></td>
    <td style="text-align:
    right;"><%= o.Field(Of Int32)("OrderCo unt").ToString( "N0") %></td>
    <td style="text-align:
    right;"><%= o.Field(Of Int64)("PacketT otal").ToString ("N0") %></td>
    <td style="text-align:
    right;"><%= o.Field(Of Decimal)("Total Sold").ToString ("N2") %></td>
    </tr%>
    </tbody>
    </table>
    </html>

    I want to insert a new row <tr><td>... each time the field "Descriptio n"
    changes and subtotal the "OrderCount ", "Packettota l" 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

  • Martin Honnen

    #2
    Re: LINQ to xml with grouping

    Rick wrote:
    I want to insert a new row <tr><td>... each time the field "Descriptio n"
    changes and subtotal the "OrderCount ", "Packettota l" 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:



    --

    Martin Honnen --- MVP XML

    Comment

    • Martin Honnen

      #3
      Re: LINQ to xml with grouping

      Rick wrote:
      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

      Comment

      • Rick

        #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@yaho o.dewrote in message
        news:%239722cs$ IHA.4684@TK2MSF TNGP06.phx.gbl. ..
        Rick wrote:
        >
        >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/

        Comment

        Working...