Solved

Treeview, maintain state/Viewstate when clicked

Posted on 2006-10-30
1
286 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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