Wednesday, March 28, 2012

TREEVIEW in an UPDATEPANEL

This is a simple one, I know it...

I have a treeview inside of an updatepanel. The treeview is recursively populated from a database table... Everything works properly, except...
When I select a node, the whole thing loads again underneat it...

This is the code that fills the treeview control...

Protected Sub fillTree(ByVal n As TreeNode, ByVal pid As Integer)
Dim sql As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlcon").ToString)
sql.Open()
Dim cmd As SqlDataReader = New SqlCommand("SELECT * FROM quarem_PortfolioFolders WHERE OwnerID='" & Web.Security.Membership.GetUser.ProviderUserKey.ToString & "' AND FolderParent=" & pid, sql).ExecuteReader

While cmd.Read
Dim newnode As New TreeNode(cmd("FolderName").ToString, cmd("FolderID"))
fillTree(newnode, cmd("FolderID"))
If IsDBNull(n) Then
portfolders.Nodes.Add(newnode)
newnode.Expanded = False
newnode.Value = cmd("FolderID")
newnode.SelectAction = TreeNodeSelectAction.Select
Else
n.ChildNodes.Add(newnode)
newnode.Expanded = False
newnode.Value = cmd("FolderID")
newnode.SelectAction = TreeNodeSelectAction.Select
End If
End While

cmd.Close()
sql.Close()
End Sub

This runs in Page_Load.

My SelectedNodeChanged sub simple updates the updatepanel that houses a repeater.
As I said, everything works great except that I get the tree loading itself over and over again!

Any suggestions?

I am truly sorry for wasting everyone's time! LOL

Obviously, the answer is IF NOT ISPOSTBACK...
I thought the directive was set, and when I went back to look at the code, I noticed...

Again... if you read this, PLEASE accept my apology!

No comments:

Post a Comment