Solved

Treeview, maintain state/Viewstate when clicked

Posted on 2006-10-30
1
284 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now