Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3985
  • Last Modified:

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

0
webressurs
Asked:
webressurs
1 Solution
 
Jens FiedererTest Developer/ValidatorCommented:
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.
0
 
David H.H.LeeCommented:
webressurs ,
You can use repeater's ItemTemplate and AlternatingItemTemplate. Here's the solution :
<asp:Repeater ID="rptArtikkel" Runat="server">
                        <HeaderTemplate>
                              <table width="100%">
                        </HeaderTemplate>
                        <ItemTemplate>
                              <tr>
                                    <td>
                                          YOUR EXISTING CODE
                                    </td>
                        </ItemTemplate>
                        <AlternatingItemTemplate>
                              <td>
                                    ANOTHER EXISTING CODE
                              </td>
                              </tr>
                        </AlternatingItemTemplate>
                        <FooterTemplate>
                              </table>
                        </FooterTemplate>
                  </asp:Repeater>

EXISTING CODE is referred your current table layout :
<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>

Anyway, i will prefer use datalist solve this similiar case. You can use datalist's RepeatColumn and RepeatDirection property to control the desired layout easily.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now