Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2010, 05:22 AM
Authorized User
 
Join Date: Jan 2010
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default Repeaters inside repeaters

I wanted to display a <ul> with a list of genres, and within this, another <ul> with review titles, and I believe you can nest repeaters, but I have looked around for code and finding it a bit tricky. I use VB. I am up to chapter 15 and haven't seen an example of this yet, so if you give an example later, forgive me.

regards

Adam
 
Old March 22nd, 2010, 05:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Adam,

Take a look at the TIO exercise on page 439 (Chapter13). It shows how to nest a BulletedList control inside a Repeater. You can do the exact same thing to nest two repeater controls. Inside the nested Repeater you can use stuff like Eval just as you do on the other Repeater.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 22nd, 2010, 08:50 PM
Authorized User
 
Join Date: Jan 2010
Posts: 31
Thanks: 5
Thanked 2 Times in 2 Posts
Default

Thanks Imar, unfortunately, the server I am using is only running .net 2.0 so I cant use Linq. After spending most of the day looking around, I eventually got it done with itemDataBinding and a horrible amount of code. I can see why you use linq for your examples. If anyone else wants it, here it is;

Code:
'aspx

  <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <b><asp:Label ID="Label1" runat="server" Text='<%# eval("[name]") %>'></asp:Label></b><br />
            <asp:Repeater ID="Repeater2" runat="server">
            
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# eval("title") %>'></asp:Label><br />
                </ItemTemplate>
            </asp:Repeater>
           <br />
        </ItemTemplate>
    </asp:Repeater>


'code behind

Imports System.Data
Imports System.Data.SqlClient

Partial Class management_hook_in
    Inherits System.Web.UI.Page

    Dim OrderRelation As DataRelation


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim dsResults As DataSet
        Dim daGenres As SqlDataAdapter
        Dim daReviews As SqlDataAdapter


        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("PlanetWroxConnectionString1").ConnectionString)


        dsResults = New DataSet
        '
        daGenres = New SqlDataAdapter
        daGenres.SelectCommand = con.CreateCommand()
        daGenres.SelectCommand.CommandType = CommandType.Text
        daGenres.SelectCommand.CommandText = "SELECT * FROM genre"
        daGenres.Fill(dsResults, "Genres")
        '
        daReviews = New SqlDataAdapter
        daReviews.SelectCommand = con.CreateCommand()
        daReviews.SelectCommand.CommandType = CommandType.Text
        daReviews.SelectCommand.CommandText = "SELECT * FROM [review]"
        daReviews.Fill(dsResults, "Reviews")
        '
        'we now have the two tables.
        'create a relationship between the two - the common column is genreID
        '
        OrderRelation = New DataRelation("OrderID_Relation", dsResults.Tables("Genres").Columns("ID"), dsResults.Tables("Reviews").Columns("GenreID"))
        OrderRelation.Nested = True
        '
        'bind the data to the parent repeater
        '
        Me.Repeater1.DataSource = dsResults.Tables("Genres")
        Me.Repeater1.DataBind()

    End Sub




    Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound


        Dim dv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
        If dv IsNot Nothing Then
            Dim repeater2 As Repeater = TryCast(e.Item.FindControl("repeater2"), Repeater)
            If repeater2 IsNot Nothing Then
                repeater2.DataSource = dv.CreateChildView(OrderRelation)
                repeater2.DataBind()
            End If
        End If





    End Sub


End Class

Last edited by AdamPembs; March 22nd, 2010 at 09:03 PM.. Reason: to add code





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Repeaters, need inner rptr to know which... thenoseknows ASP.NET 2.0 Professional 0 May 27th, 2007 08:31 PM
Nested Repeaters darylh2004 ASP.NET 2.0 Basics 0 July 6th, 2006 04:14 AM
Nested Repeaters three deep? Silfverduk ASP.NET 2.0 Basics 0 June 21st, 2006 01:14 PM
Nested Repeaters to create hierarchy Lord__Chaos ASP.NET 2.0 Basics 0 May 26th, 2006 12:37 PM
master/detail pages with Repeaters ben21 Classic ASP Basics 0 September 19th, 2005 06:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.