Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 May 26th, 2006, 12:37 PM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nested Repeaters to create hierarchy

Hey everyone :)

I've got a problem with creating a hierarchy using nested repeaters.



Code:
<asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <%# DataBinder.Eval(Container.DataItem, "[\"FullName\"]") %>
                    <br />
                    <asp:Repeater ID="Repeater2" runat="Server" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("ParentChild") %>'>
                        <ItemTemplate>

                                <%# DataBinder.Eval(Container.DataItem, "[\"FullName\"]") %>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:Repeater>  


protected void Page_Load(object sender, EventArgs e)
    {
        string strSql = "SELECT [ID], [Parent_ID], FullName, FirstName, LastName FROM Individual";
        SqlConnection conn = new SqlConnection("Data Source=localhost,2819;Initial Catalog=Connections;Integrated Security=True");
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter();
        SqlCommand cmd = new SqlCommand(strSql, conn);
        cmd.CommandType = CommandType.Text;

        da.SelectCommand = cmd;
        da.Fill(ds);

        da.Dispose();
        ds.DataSetName = "Individuals";
        ds.Tables[0].TableName = "Individual";
        DataRelation relation = new DataRelation("ParentChild",
        ds.Tables["Individual"].Columns["ID"],
        ds.Tables["Individual"].Columns["Parent_ID"],
        true);
        relation.Nested = true;
        ds.Relations.Add(relation);


        Repeater1.DataSource = ds.Tables["Individual"];
        Repeater1.DataBind();
        conn.Close();

    }
Basically what happens, is it creates and displays the relationships...but for example, does this:

Dave Richardson
Vincent Finley
    Bryan Siders
    Hank Hill
    Wes Craven
Bobby Brown
Bryan Siders
    John Doe
    Karla Norwood
Hank Hill
Wes Craven
    Stewie Griffin
Stewie Griffin
John Doe
Jim Cardwell
    Dave Richardson
    Vincent Finley
    Bobby Brown
Karla Norwood

In other words, after it lists "Karla Norwood" as a child of "Bryan Siders"...it shouldn't list Karla Norwood later on in the list as a Master having no children! Can anyone help? This is how the output SHOULD be:

Jim Cardwell
    Dave Richardson
    Vincent Finley
        Bryan Siders
            John Doe
            Karla Norwood
        Hank Hill
        Wes Craven
            Stewie Griffin
    Bobby Brown



Thanks in advance!!!







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
dynamic menu from nested repeaters Jacko ASP.NET 1.0 and 1.1 Professional 1 March 6th, 2006 06:51 AM





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