Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 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 Professional 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 September 3rd, 2007, 02:57 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:I'm Doug?? ;) or there is a post that I didn't see??
Mea culpa, Gonzalo. I shouldn't be looking at four P2P posts at the same time, while trying to write an article and a reply to this post....

It's useless in the sense that it isn't an answer to the OP's question, something that is always important to keep in mind in public forums. From a theoretical point of view, or a code-coolness view, it *is* useful of course..... ;)

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 3rd, 2007, 04:25 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot for yours help!

Imar, I don't use C# so... I can't use anonymous delegate. I saw examples like these on my web searches but couldn't make this work on VB.

I spent all my afternoon with this!

With my first solution (That I wrote here) I saw that i make a postback every time that I click on treeview "+" (demand Icon).
And only then the treeview bind subcategories.

With a small change off code I have what I want!

Code:
Private Sub BindTreeView()
            Dim CategTable As DataTable = MySite.BLL.Articles.Category.GetCategoriesTable()
            PopulateNodes(CategTable, tvCategories.Nodes, 0)
        End Sub

Private Sub PopulateNodes(ByVal dt As DataTable, _
      ByVal nodes As TreeNodeCollection, ByVal Parent As Integer)
            For Each dr As DataRow In dt.Rows
                If dr("ParentID") = Parent Then

                    Dim tn As New TreeNode()
                    tn.Text = dr("Name").ToString()
                    tn.Value = dr("CategoryID").ToString()
                    nodes.Add(tn)

                    If dt.Select("ParentID=" & dr("CategoryID").ToString()).Length > 0 Then
                        PopulateNodes(dt, tn.ChildNodes, dr("CategoryID").ToString())
                    End If

                End If
            Next
        End Sub
With this I don't have postback on my treeview! But I don't know if it is good politic have a function call inside this same function!
The solution worked but I'll appreciate your opinion about this!


BTW I used "DataTable" just for test... I could a list(of T) with a double "for" to do the same like we conclude some posts earlier

Thanks one more time!
 
Old September 4th, 2007, 12:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:But I don't know if it is good politic have a function call inside this same function!
It certainly is. It's called a recursive function where a function calls itself. Often used to solve these kind of hierarchical problems. More info: http://en.wikipedia.org/wiki/Recursi...ter_science%29

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old September 4th, 2007, 06:51 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much Imar!

I was surprised with the simplicity of the function that i built and had doubts about this!

If anyone want to retrieve a datatable with "CategoryID, Name, ParentID" and make a hierarchical treeview without postback can use the last function on this thread!






Similar Threads
Thread Thread Starter Forum Replies Last Post
"A command with that name already exists" Aaron Edwards Visual Studio 2005 2 March 9th, 2007 03:45 PM
File already exists srsandhu ASP.NET 1.0 and 1.1 Basics 1 February 14th, 2007 08:43 PM
table already exists mussa MySQL 1 July 13th, 2006 03:01 AM
'exists' dilemma defiant SQL Server 2000 4 June 27th, 2003 07:26 AM





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