CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    VB.Net repeater group by

    I have the following code in my vb.net:

    Code:
     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                    'Start Bind PO Details and Trailers
                        dsRepeater = RetrieveDCDetails(Session.Item("UserID"), Session.Item("DCNo"))
                        dsRepeater.EnforceConstraints = False
    
                        '   Add Relationship
                        rel = New DataRelation("DCDetailsTrailersRel",dsRepeater.Tables("DCAllowanceDetails").Columns("DCID"), 
     dsRepeater.Tables("DCallowanceTrailers1").Columns("DCID"))
                        dsRepeater.Relations.Add(rel)
                        rel = New DataRelation("DCDetailsTrailersRel2",dsRepeater.Tables("DCAllowanceDetails").Columns("SubLineNo2"), dsRepeater.Tables("DCAllowanceTrailers1").Columns("SubLineNo2"))
                        dsRepeater.Relations.Add(rel)
                      
    
                        RepDCDetails.DataSource = dsRepeater.Tables("DCAllowanceDetails").DefaultView
                        RepDCDetails.DataBind()
                       
                        'Update Status From Unread to Read to database
    
    
                    End If
    
    
    
                Catch ex As Exception
                End Try
    
            End Sub
    
    
     Private Function RetrieveDCDetails(ByVal callerUserID As String, ByVal DCID As String) As DataSet
                Dim objDB As New clsDB
                Try
                    Dim sql As String = [String].Empty
    
                    sql = "SELECT * FROM Trn_DC_Details "
                    sql &= "WHERE DCID='" + DCID + "' ORDER BY [LineNo] ;"
                
                    sql &= "SELECT * FROM Trn_DC_Trailers "
                    sql &= "WHERE DCID='" + DCID + "' ORDER BY [SubLineNo2] ;"
    
                    objDB.OpenDataSet(dsRepeater, sql)
                    dsRepeater.Tables(0).TableName = "DCAllowanceDetails"
                    dsRepeater.Tables(1).TableName = "DCAllowanceTrailers1"
                    dsRepeater.DataSetName = "DCAllowanceDetails"
           
                    Return dsRepeater
                Catch e As Exception
                  
                Finally
                    objDB = Nothing
                End Try
            End Function 'RetrievePurchaseOrderDetails
    Then I have the following repeater in my web layout:


    Code:
    <asp:Repeater runat="server" id="RepDCDetails">
    <ItemTemplate>
    <tr><td style="border-bottom: 1px; border-right-style: none;">
    <asp:Label ID="Label17" runat="server" Text="<br/>"></asp:Label></td></tr>
    <tr>
    <td align="left" colspan="4" class="tableitem" width="7&#37;" style="border-right: none; border-top: none; border-left: none; border-bottom: none; font-size: 9px; background-color:white" >
    <%#Container.DataItem("ClassName")%>
    </td>
    </tr>
                                                                    
    <tr><td align="right" colspan="1" class="tableitem" width="7%" style="border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; font-size: 9px;" >
            <%#Container.DataItem("GRNNo")%></td>
    <td align="right" colspan="1" class="tableitem" width="4%" style="border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; font-size: 9px;" >
             <%#Format(DataBinder.Eval(Container.DataItem, "GRNDate"), "dd/MM/yy")%></td></tr>
                                                       
                                                  
    <asp:Repeater runat="server" id="RepDCTrailers">
    <ItemTemplate>
    <tr>
    <td align="center" colspan="4" class="tableitem" width="7%" style="border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; font-size: 9px;" >STYLE TOTAL</td>
    <td align="left" colspan="1" class="tableitem" width="4%" style="border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; font-size: 9px;" >
    <%#Container.DataItem("Style_RUnit")%></td>
    </tr>  
     </ItemTemplate>
    </asp:Repeater>
    </ItemTemplate>
    </asp:Repeater>
    In the repeater, we can see that there are three item which are Class Name,GRNNo and Style_RUnit.Currently each GRNNo will display one ClassName and RUNit. But what I want is if the SubLineNo2 of GRNNo is same, then className and RUnit should only be display one time until the different SubLineNo2 of GRNNo occured.

    Current Output:
    Class1
    GRN1
    Style1

    Class1
    GRN2
    Style1


    Expected Output:
    Class1
    GRN1
    GRN2
    Style1

    Class2
    GRN3
    GRN4
    GRN5
    Style2

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB.Net repeater group by

    I think you want to GROUP items. Not sure of the input, from your output.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured