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
Solved

Treeview, maintain state/Viewstate when clicked

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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