Link to home
Start Free TrialLog in
Avatar of webressurs
webressursFlag for Norway

asked on

List products in 2 columns (repeater)?

I have made a repeater that lists products like this:

| Product 1 |
| Product 2 |
| Product 3 |
| Product 4 |
| Product 5 |
| Product 6 |

...and so on

But, I want to list the products in 2 columns like this:

| Product 1 | Product 2|
| Product 3 | Product 4|
| Product 5 | Product 6|
.
.
And so on....



This is the code I got so far, hope someone please can help me:



*********************
ASPX-FILE
*********************

<asp:repeater id="rptArtikkel" Runat="server">
    <ItemTemplate>
        <table>
            <tr>
                <td width="99%">
                    <h2><%#Container.dataitem("title")%></h2><br />
                    <%#Container.dataitem("ingress")%><br />
                    <asp:LinkButton runat="server" id="lnkDetalj" Text="More>>" CommandName="cmdLesMer" CommandArgument='<%#Container.dataitem("artID")%>' Visible='<%#lesmer(Container.dataitem("body"))%>' /><br /><br />
                </td>
                <td width="1%" align="center">
                    <a href="/ld/detail.aspx?artID=<%#Container.dataitem("artID")%>">
                    <asp:Image Width="86" Height="86" ImageUrl='<%#Container.dataitem("image")%>' Visible='<%#bildefunksjon(Container.DataItem("image"))%>' Runat="Server" ID="Image1"/></a><br />
                    <%#Container.dataitem("imagetext")%>      
                </td>
            </tr>
        </table>
</ItemTemplate>
</asp:repeater>


*********************
ASPF.VB-FILE
*********************

Private Sub HentArtikkel(ByVal inputCatID)

        Dim SQL As String = "select title,ingress,body,artID, " & _
                            "(select top 1 path from tblImage where tblImage.artID = tblArticle.artID) as image, " & _
                            "(select top 1 text from tblImage where tblImage.artID = tblArticle.artID) as imagetext " & _
                            "from tblArticle where active='1' and catID=@catID and custID=@custID"

        Dim conn As New SqlConnection(variables.ConnString)
        Dim cmd As New SqlCommand(SQL, conn)

        Dim parameter1 As New SqlParameter("@catID", inputCatID)
        Dim parameter2 As New SqlParameter("@custID", variables.custID)
        cmd.Parameters.Add(parameter1)
        cmd.Parameters.Add(parameter2)
        cmd.Connection.Open()
        Dim DT As New DataTable()
        Dim DA As New SqlDataAdapter(cmd)
        DA.Fill(DT)

        If DT.Rows.Count() = 1 Then 'If only one article, show detail
            Dim varArtID As Int16 = DT.Rows(0).Item("artID")
            cmd.Connection.Close()
            cmd.Dispose()
            conn.Dispose()
            Response.Redirect("/ld/detail.aspx?catID=" & inputCatID & "&artID=" & varArtID)
        Else
            Me.rptArtikkel.DataSource = DT
            Me.rptArtikkel.DataBind()
        End If

        cmd.Connection.Close()
        cmd.Dispose()
        conn.Dispose()

End Sub

Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

A fairly simple approach would be to define a structure with 2 properties for each column corresponding to your datarow: artid1, artid2, image1, image2, etc.

Create a List (2005) or ArrayList (2003) of these structures, and initialize them with values from your query.

Then bind the list to your repeater control.
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial