Solved

Treeview, maintain state/Viewstate when clicked

Posted on 2006-10-30
1
292 Views
Last Modified: 2012-08-14
here is my codebehind:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        TreeView1.Nodes.Clear()
        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")

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

                tnFacilityType.ChildNodes.Add(tnFacility)

                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")

                    tnFacilityProject.ChildNodes.Add(tnFacilityProjects)
                Next

                If tnFacilityProject.ChildNodes.Count > 0 Then
                    tnFacility.ChildNodes.Add(tnFacilityProject)
                End If
            Next
        Next

    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" />
        </asp:TreeView>
    </div>
</asp:Content>



=================================================================

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..
0
Comment
Question by:EchoBinary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 total points
ID: 17838192
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

John
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question