Hi,
Here is my code
.aspx
-------------------------------------------------------------------------------------------------------
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="mainpnl" UpdateMode="Conditional" >
<ContentTemplate>
<div>
<asp:TreeView
ID="TreeView1"
ExpandDepth="0"
PopulateNodesFromClient="true"
ShowLines="true"
ShowExpandCollapse="true"
runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
codebehind
---------------------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateRootLevel()
End If
End Sub
Private Sub PopulateRootLevel()
Dim objConn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=True;")
Dim objCommand As New SqlCommand("select Id,CatName,(select count(*) FROM tbl_category " _
& "WHERE parentid=sc.id) childnodecount FROM tbl_category sc where parentId=0 and Projid=1", objConn)
Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, TreeView1.Nodes)
End Sub
Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
Dim objConn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=True;")
Dim objCommand As New SqlCommand("select id,CatName,(select count(*) FROM tbl_category " _
& "WHERE parentid=sc.id) childnodecount FROM tbl_category sc where parentID=@parentID and Projid=1", objConn)
objCommand.Parameters.Add("@parentID", SqlDbType.Int).Value = parentid
Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, parentNode.ChildNodes)
End Sub
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("CatName").ToString()
tn.Value = dr("id").ToString()
nodes.Add(tn)
'If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub
Here is the output on page load and user clicking. when ever user clicking on node (cat 2.1.1), it is creating one more node (c at 2.1) and appending to parent node. but it's not suppose to create any node. if i keep treeview outside update panel..it is working fine but page is reloading (obvious)...I want treeview should work partial postback...
On Page load
After clicking on node