Treeview, maintain state/Viewstate when clicked

here is my codebehind:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim dsHamotFacTree As Data.DataSet = Nothing

        Dim tnFacilityType As TreeNode = Nothing
        Dim tnFacility As TreeNode = Nothing
        Dim tnFacilityProject As TreeNode = Nothing
        Dim tnFacilityProjects As TreeNode = Nothing

        Dim drFacilityType As Data.DataRow = Nothing
        Dim drFacility As Data.DataRow = Nothing
        Dim drFacilityProjects As Data.DataRow = Nothing

        dsHamotFacTree = gfunctions.get_dataset(gfunctions.sConnectionString, "SELECT * FROM Fac_type ORDER BY Fac_type_Desc", "fac_type")
        dsHamotFacTree = gfunctions.get_dataset(gfunctions.sConnectionString, "SELECT * FROM Facility_master", "fac_mast", dsHamotFacTree)
        dsHamotFacTree = gfunctions.get_dataset(gfunctions.sConnectionString, "SELECT Proj_Rec_ID, Fac_Rec_ID, Project_Code FROM Projects", "prj_mast", dsHamotFacTree)

        With dsHamotFacTree
            .Relations.Add("fac_type_mast", dsHamotFacTree.Tables("fac_type").Columns("Fac_type_id"), dsHamotFacTree.Tables("fac_mast").Columns("Fac_type_id"))
            .Relations.Add("fac_mast_prj", dsHamotFacTree.Tables("fac_mast").Columns("Fac_Rec_ID"), dsHamotFacTree.Tables("prj_mast").Columns("Fac_Rec_ID"))

        End With

        For Each drFacilityType In dsHamotFacTree.Tables("fac_type").Rows
            tnFacilityType = New TreeNode
            tnFacilityType.Text = drFacilityType("Fac_Type_Desc")
            tnFacilityType.Value = drFacilityType("Fac_Type_ID")

            For Each drFacility In drFacilityType.GetChildRows("fac_type_mast")
                tnFacility = New TreeNode
                tnFacility.Text = drFacility("Facility_Desc")
                tnFacility.Value = drFacility("Fac_Rec_ID")


                tnFacilityProject = New TreeNode
                tnFacilityProject.Text = "Projects"
                tnFacilityProject.Value = "p"
                For Each drFacilityProjects In drFacility.GetChildRows("fac_mast_prj")
                    tnFacilityProjects = New TreeNode
                    tnFacilityProjects.Text = drFacilityProjects("Project_Code")
                    tnFacilityProjects.Value = drFacilityProjects("Proj_Rec_ID")


                If tnFacilityProject.ChildNodes.Count > 0 Then
                End If

    End Sub

here is my aspx:

<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div style="width: 240px; height: 400px; overflow: scroll;">
        <asp:TreeView ID="TreeView1" NodeWrap="true" runat="server" Height="191px" ImageSet="Arrows" ShowLines="True" Width="220px">
            <ParentNodeStyle Font-Bold="False" />
            <HoverNodeStyle Font-Underline="False" ForeColor="#5555DD" Font-Bold="True" />
            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
                VerticalPadding="0px" />
            <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"
                NodeSpacing="0px" VerticalPadding="0px" />


what i need to do is be able to is click on a node and once the page refreshes the state of the treeview is the same as in the same trees are expanded as before etc.etc..
Who is Participating?
jnhorstConnect With a Mentor Commented:
In your page load event, only load up the tree view when the page is not a postback, like this:

If Not Me.IsPostBack Then
     '... all your code here to load up the tree view.
End If

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.