Treeview Control

Discussion in 'ASP .Net Web Controls' started by Schoo, Jan 19, 2004.

  1. Schoo

    Schoo Guest

    I am successfully using the Microsoft.Web.UI.WebControls.dll but I can't get
    the treeview control to run code when a node is selected. I read the msdn
    online documentation and am doing this with code-behind in VB. Here is the
    code that I am using:
    ===========================================
    <ie:treeview runat="server" id="treeview1"
    onselectedindexchanged="SelectedIndexChanged">
    <ie:treenode ..../>
    </ie.treeview>

    Public sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    TreeViewSelectEventArgs)
    Label1.Text = "Selected " + e.NewNode.ToString + " (old Node index=" +
    e.OldNode.ToString + ")"
    End Sub
    ============================================
    I need to fill a grid dynamically as a user clicks on an item. So, I need
    an event that will respond and a way to use a key field so I can use that
    information to pass to the grid. Any ideas or samples would be appreciated.

    Scott
    Schoo, Jan 19, 2004
    #1
    1. Advertising

  2. Schoo

    ONIL@ Guest

    Hi, Schoo!
    set Treeview autopostback=true

    Public sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    TreeViewSelectEventArgs)
    Label1.Text
    =Treeview.GetNodeFromIndex(Treeview.SelectedNodeIndex.ToString).Text
    End Sub

    Best Regards!
    --
    ONil@.
    MX.

    "Schoo" <-hc.com> wrote in message
    news:...
    > I am successfully using the Microsoft.Web.UI.WebControls.dll but I can't

    get
    > the treeview control to run code when a node is selected. I read the msdn
    > online documentation and am doing this with code-behind in VB. Here is

    the
    > code that I am using:
    > ===========================================
    > <ie:treeview runat="server" id="treeview1"
    > onselectedindexchanged="SelectedIndexChanged">
    > <ie:treenode ..../>
    > </ie.treeview>
    >
    > Public sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    > TreeViewSelectEventArgs)
    > Label1.Text = "Selected " + e.NewNode.ToString + " (old Node index=" +
    > e.OldNode.ToString + ")"
    > End Sub
    > ============================================
    > I need to fill a grid dynamically as a user clicks on an item. So, I need
    > an event that will respond and a way to use a key field so I can use that
    > information to pass to the grid. Any ideas or samples would be

    appreciated.
    >
    > Scott
    >
    >
    ONIL@, Jan 20, 2004
    #2
    1. Advertising

  3. Schoo

    Schoo Guest

    OK, you were right, I needed to set the autopostback property to true, but I
    still can't get it to run the procedure. I can tell it is going back to the
    server each time because I can see the page resetting, but I have a 'break'
    set on the "Public Sub..." line of code and it is not stopping in debug
    mode.

    Here are the important code parts for your review:
    ====================================================
    <ie:Treeview runat="server" id="Treeview1" AutoPostBack="True">
    Also tried:
    <ie:Treeview runat="server" id="Treeview1" AutoPostBack="True"
    onselectedindexchanged="SelectedIndexChanged">

    Public Sub mySelectChange(ByVal sender As Object, ByVal e As
    TreeViewSelectEventArgs)
    Label1.Text= .... <the code you had... it never gets here anyway>
    End Sub
    ====================================================
    Running the page, the treeview displays the simple XML file properly.

    While we are working to get this 'click event' to work, I am going to start
    working on the 'real' xml file that will actually be used. I noticed that
    the sample does not provide key/index values from the dataset, but I will
    need them for what I want to do. Basically I have to pass a GUID through
    the treeview control from the dataset. Please let me know what you think
    about how to do that.

    Thanks,

    Scott

    "ONIL@" <> wrote in message
    news:...
    >
    > Hi, Schoo!
    > set Treeview autopostback=true
    >
    > Public sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    > TreeViewSelectEventArgs)
    > Label1.Text
    > =Treeview.GetNodeFromIndex(Treeview.SelectedNodeIndex.ToString).Text
    > End Sub
    >
    > Best Regards!
    > --
    > ONil@.
    > MX.
    >
    > "Schoo" <-hc.com> wrote in message
    > news:...
    > > I am successfully using the Microsoft.Web.UI.WebControls.dll but I can't

    > get
    > > the treeview control to run code when a node is selected. I read the

    msdn
    > > online documentation and am doing this with code-behind in VB. Here is

    > the
    > > code that I am using:
    > > ===========================================
    > > <ie:treeview runat="server" id="treeview1"
    > > onselectedindexchanged="SelectedIndexChanged">
    > > <ie:treenode ..../>
    > > </ie.treeview>
    > >
    > > Public sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    > > TreeViewSelectEventArgs)
    > > Label1.Text = "Selected " + e.NewNode.ToString + " (old Node index="

    +
    > > e.OldNode.ToString + ")"
    > > End Sub
    > > ============================================
    > > I need to fill a grid dynamically as a user clicks on an item. So, I

    need
    > > an event that will respond and a way to use a key field so I can use

    that
    > > information to pass to the grid. Any ideas or samples would be

    > appreciated.
    > >
    > > Scott
    > >
    > >

    >
    >
    Schoo, Jan 20, 2004
    #3
  4. Hi Schoo,

    Thank you for posting in the community! My name is Jeffrey, and I will be
    assisting you on this issue.
    Based on the posts between you and ONIL, I think you meet the strange
    problem that SelectedIndexChanged event does not firel

    ==========================================================
    After review your code snippet, I found that you add your event handler
    mySelectChange to SelectedIndexChanged event through code:
    onselectedindexchanged="SelectedIndexChanged", I think you your event
    handler's name is not correct, please try to use:
    onselectedindexchanged="mySelectChange"

    If your event handler still does not fire, I think you may set breakpoint
    in Page_load to determine if postback occurs.

    Also, you may try to add the event handler in the IDE.

    The last possibility that I can think of is that maybe you initailized your
    TreeView control programmaticly in Page_load, so when every postback, the
    TreeView is re-initailized, so the SelectedIndexChanged event will not fire.

    For your further XML logic, I am not sure if it related to your problem,
    please apply my suggestion above and let me know if it helps resolve your
    problem.
    If it still does not work, please provide me more detailed information of
    your web application.

    =========================================================
    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 21, 2004
    #4
  5. Schoo

    Schoo Guest

    First, I put a page break on the Page_Load event and everytime I click on an
    item in the treeview control, this event indeed does fire.

    I tried a couple new combinations to call the procedure from the click event
    of the control and none of them work to follow a click event. However, I
    suppose I could use the Page_Load procedure to return data on the item
    selected. That isn't really technically the correct way to do it and I
    would prefer not to 'code around' issues like this.

    Look, it's simple... I have a treeview control on a form. It uses an XML
    file to populate it and I can see where that file may get pretty large. I
    shouldn't have to post back to the server to put some text in a label
    control from the treeview control, should I? Here is ALL THE CODE that I am
    using, feel free to run this on your computer and tell me what is wrong, or
    do a demo yourself and send me the code:

    ================================================================
    Imports System.Data.SqlClient
    Imports Microsoft.Web.UI.WebControls

    Public Class HRReview
    Inherits System.Web.UI.Page
    Dim connPeople As String =
    "DATABASE=Intranet;SERVER=mahc_sql3;UID=sa;PWD=;"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Page.IsPostBack Then
    Label1.Text =
    Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex.ToString).Text
    End If
    End Sub
    Public Sub TreeView1_SelectedIndexChanged(ByVal sender As Object, ByVal
    e As TreeViewSelectEventArgs)
    'Label1.Text = "Selected " + e.NewNode.ToString + " (old Node
    index=" + e.OldNode.ToString + ")"
    Label1.Text =
    Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex.ToString).Text

    End Sub
    End Class
    .............................................................................
    ...................
    <%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls"
    Assembly="Microsoft.Web.UI.WebControls" %>
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="HRReview.aspx.vb"
    Inherits="Forms.HRReview"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>HRReview</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <ie:TreeView runat="server" ID="Treeview1" AutoPostBack="True"
    onselectedindexchanged="SelectedIndexChanged">
    <ie:TreeNode ImageUrl="images/root.gif" TreeNodeSrc="XML/state_city.xml"
    Text="North America"
    Expanded="True" ExpandedImageUrl="images/folderopen.gif"
    Expandable="CheckOnce"></ie:TreeNode>
    </ie:TreeView>
    <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 400px; POSITION:
    absolute; TOP: 32px" runat="server"
    Width="232px" Height="80px">Label</asp:Label>
    </form>
    </body>
    </HTML>
    .............................................................................
    ...................
    <TREENODES>
    <treenode Text="Michigan">
    <treenode Text="Detroit" >
    <treenode text="Martha" />
    <treenode text="Bob">
    </treenode>
    </treenode>
    <treenode Text="Farmington" />
    <treenode Text="Southfield" />
    </treenode>
    <treenode Text="Washington" >
    <treenode Text="Bellevue" />
    <treenode Text="Redmond" />
    <treenode Text="Woodinville" />
    </treenode>
    </TREENODES>
    ================================================================


    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:dkzkhr#...
    >
    > Hi Schoo,
    >
    > Thank you for posting in the community! My name is Jeffrey, and I will be
    > assisting you on this issue.
    > Based on the posts between you and ONIL, I think you meet the strange
    > problem that SelectedIndexChanged event does not firel
    >
    > ==========================================================
    > After review your code snippet, I found that you add your event handler
    > mySelectChange to SelectedIndexChanged event through code:
    > onselectedindexchanged="SelectedIndexChanged", I think you your event
    > handler's name is not correct, please try to use:
    > onselectedindexchanged="mySelectChange"
    >
    > If your event handler still does not fire, I think you may set breakpoint
    > in Page_load to determine if postback occurs.
    >
    > Also, you may try to add the event handler in the IDE.
    >
    > The last possibility that I can think of is that maybe you initailized

    your
    > TreeView control programmaticly in Page_load, so when every postback, the
    > TreeView is re-initailized, so the SelectedIndexChanged event will not

    fire.
    >
    > For your further XML logic, I am not sure if it related to your problem,
    > please apply my suggestion above and let me know if it helps resolve your
    > problem.
    > If it still does not work, please provide me more detailed information of
    > your web application.
    >
    > =========================================================
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Schoo, Jan 21, 2004
    #5
  6. Schoo

    Schoo Guest

    Barry,

    Thank you for the idea. I tried it and it still does not get to the "Public
    Sub SelectedIndexChanged(...)" procedure. For clarity, here is the code I
    ran:

    ===============================================================
    Imports System.Data.SqlClient
    Imports Microsoft.Web.UI.WebControls

    Public Class HRReview
    Inherits System.Web.UI.Page
    Dim connPeople As String =
    "DATABASE=Intranet;SERVER=mahc_sql3;UID=sa;PWD=;"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    End Sub
    Public Sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    TreeViewSelectEventArgs)
    'Label1.Text = "Selected " + e.NewNode.ToString + " (old Node
    index=" + e.OldNode.ToString + ")"
    Label1.Text =
    Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex.ToString).Text
    End Sub
    End Class
    .............................................................................
    ...................
    <%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls"
    Assembly="Microsoft.Web.UI.WebControls" %>
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="HRReview.aspx.vb"
    Inherits="Forms.HRReview"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>HRReview</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <ie:TreeView runat="server" ID="Treeview1" AutoPostBack="True"
    onselectedindexchanged="SelectedIndexChanged">
    <ie:TreeNode ImageUrl="images/root.gif" TreeNodeSrc="XML/state_city.xml"
    Text="North America"
    Expanded="True" ExpandedImageUrl="images/folderopen.gif"
    Expandable="CheckOnce"></ie:TreeNode>
    </ie:TreeView>
    <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 400px; POSITION:
    absolute; TOP: 32px" runat="server"
    Width="232px" Height="80px">Label</asp:Label>
    </form>
    </body>
    </HTML>
    .............................................................................
    ...................
    <TREENODES>
    <treenode Text="Michigan">
    <treenode Text="Detroit" >
    <treenode text="Martha" />
    <treenode text="Bob">
    </treenode>
    </treenode>
    <treenode Text="Farmington" />
    <treenode Text="Southfield" />
    </treenode>
    <treenode Text="Washington" >
    <treenode Text="Bellevue" />
    <treenode Text="Redmond" />
    <treenode Text="Woodinville" />
    </treenode>
    </TREENODES>
    ====================================================================
    Please let me know what you think. I need a solution for this issue. :)

    Scott


    "Barry Forrest" <> wrote in message
    news:...
    > Schoo
    >
    > Your aspx page says:
    > " <ie:TreeView runat="server" ID="Treeview1" AutoPostBack="True"

    onselectedindexchanged="SelectedIndexChanged"> "
    > your code behind doesn't have "SelectedIndexChanged".
    > It has "TreeView1_SelectedIndexChanged"
    > Change one to match the other and it should work properly.
    >
    > Barry
    >
    > ----- Schoo wrote: -----
    >
    > First, I put a page break on the Page_Load event and everytime I

    click on an
    > item in the treeview control, this event indeed does fire.
    >
    > I tried a couple new combinations to call the procedure from the

    click event
    > of the control and none of them work to follow a click event.

    However, I
    > suppose I could use the Page_Load procedure to return data on the

    item
    > selected. That isn't really technically the correct way to do it and

    I
    > would prefer not to 'code around' issues like this.
    >
    > Look, it's simple... I have a treeview control on a form. It uses an

    XML
    > file to populate it and I can see where that file may get pretty

    large. I
    > shouldn't have to post back to the server to put some text in a label
    > control from the treeview control, should I? Here is ALL THE CODE

    that I am
    > using, feel free to run this on your computer and tell me what is

    wrong, or
    > do a demo yourself and send me the code:
    >
    > ================================================================
    > Imports System.Data.SqlClient
    > Imports Microsoft.Web.UI.WebControls
    >
    > Public Class HRReview
    > Inherits System.Web.UI.Page
    > Dim connPeople As String =
    > "DATABASE=Intranet;SERVER=mahc_sql3;UID=sa;PWD=;"
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > If Page.IsPostBack Then
    > Label1.Text =
    > Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex.ToString).Text
    > End If
    > End Sub
    > Public Sub TreeView1_SelectedIndexChanged(ByVal sender As Object,

    ByVal
    > e As TreeViewSelectEventArgs)
    > 'Label1.Text = "Selected " + e.NewNode.ToString + " (old Node
    > index=" + e.OldNode.ToString + ")"
    > Label1.Text =
    > Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex.ToString).Text
    >
    > End Sub
    > End Class
    >

    .............................................................................
    ..
    > ...................
    > <%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls"
    > Assembly="Microsoft.Web.UI.WebControls" %><%@ Page Language="vb"

    AutoEventWireup="false" Codebehind="HRReview.aspx.vb"
    > Inherits="Forms.HRReview"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML

    4.0 Transitional//EN"><HTML><HEAD><title>HRReview</title><meta
    content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"><meta
    content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"><meta
    content="JavaScript" name="vs_defaultClientScript"><meta
    content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema"></HEAD><body MS_POSITIONING="GridLayout"><form

    id="Form1" method="post" runat="server"><ie:TreeView runat="server"
    ID="Treeview1" AutoPostBack="True"
    > onselectedindexchanged="SelectedIndexChanged"><ie:TreeNode

    ImageUrl="images/root.gif" TreeNodeSrc="XML/state_city.xml"
    > Text="North America"
    > Expanded="True" ExpandedImageUrl="images/folderopen.gif"
    > Expandable="CheckOnce"></ie:TreeNode></ie:TreeView><asp:Label

    id="Label1" style="Z-INDEX: 101; LEFT: 400px; POSITION:
    > absolute; TOP: 32px" runat="server"
    > Width="232px"

    Height="80px">Label</asp:Label></form></body></HTML>
    >

    .............................................................................
    ..
    > ...................
    > <TREENODES><treenode Text="Michigan"><treenode Text="Detroit"
    ><treenode text="Martha" /><treenode

    text="Bob"></treenode></treenode><treenode Text="Farmington" /><treenode
    Text="Southfield" /></treenode><treenode Text="Washington" ><treenode
    Text="Bellevue" /><treenode Text="Redmond" /><treenode Text="Woodinville"
    /></treenode></TREENODES>
    > ================================================================
    >
    >
    > ""Jeffrey Tan[MSFT]"" <> wrote in message
    > news:dkzkhr#...
    > >> Hi Schoo,
    > >> Thank you for posting in the community! My name is Jeffrey, and I

    will be
    > > assisting you on this issue.
    > > Based on the posts between you and ONIL, I think you meet the

    strange
    > > problem that SelectedIndexChanged event does not firel
    > >> ==========================================================

    > > After review your code snippet, I found that you add your event

    handler
    > > mySelectChange to SelectedIndexChanged event through code:
    > > onselectedindexchanged="SelectedIndexChanged", I think you your

    event
    > > handler's name is not correct, please try to use:
    > > onselectedindexchanged="mySelectChange"
    > >> If your event handler still does not fire, I think you may set

    breakpoint
    > > in Page_load to determine if postback occurs.
    > >> Also, you may try to add the event handler in the IDE.
    > >> The last possibility that I can think of is that maybe you

    initailized
    > your
    > > TreeView control programmaticly in Page_load, so when every

    postback, the
    > > TreeView is re-initailized, so the SelectedIndexChanged event will

    not
    > fire.
    > >> For your further XML logic, I am not sure if it related to your

    problem,
    > > please apply my suggestion above and let me know if it helps

    resolve your
    > > problem.
    > > If it still does not work, please provide me more detailed

    information of
    > > your web application.
    > >> =========================================================

    > > Thank you for your patience and cooperation. If you have any

    questions or
    > > concerns, please feel free to post it in the group. I am standing

    by to be
    > > of assistance.
    > >> Best regards,

    > > Jeffrey Tan
    > > Microsoft Online Partner Support
    > > Get Secure! - www.microsoft.com/security
    > > This posting is provided "as is" with no warranties and confers no

    rights.
    > >
    Schoo, Jan 22, 2004
    #6
  7. Hi Schoo,

    Thanks for your feedback.
    I feel strange that this event does not fire. I have tried your html code,
    and added a breakpoint in SelectedIndexChange event handler.
    This event does fire.

    In my test I have removed all your xml related code and image url setting
    code.
    So I recommand you create a new empty project, then add a treeview control
    onto the web form, then add the selecteditemchange event handler for it.
    Then add a breakpoint in your selecteditemchange event handler to determine
    if this event fires.

    If it really does not fire, you can try to create a new C# project do the
    same thing, to determine it this strange behavior happens again.

    At last, if it does not fire, I think you can provide me your project to
    reproduce this problem for me. I will try my best to help you.

    ===============================================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 23, 2004
    #7
  8. Schoo

    Schoo Guest

    Jeff,

    Thanks for helping me with this. I did what you said and have the same
    results. There is so little code that I wonder if this is some sort of a
    configuration issue (global.asax) on my workstation. It is acting like it
    just can't find the procedure when you click on an item in the tree. Here
    is what I am doing... I hope you notice something I am doing wrong:

    First I create a whole new web project in VS.NET with a VB back-end
    I create a subfolder off the project called "XML" and drop in my XML file
    I copy the Microsoft.Web.UI.WebControls.dll to the project's bin directory
    I Rt. Click References, then "add reference" then browse to the project's
    bin directory and select the Microsoft.Web.UI.WebControls.dll and click "OK"

    I am not adding anything from the toolbar, I just add the following code to
    the HTML tab in VS:
    ===================================================================
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
    Inherits="TreeviewTest.WebForm1"%>
    <%@ Register TagPrefix="ie" Namespace="Microsoft.Web.UI.WebControls"
    Assembly="Microsoft.Web.UI.WebControls" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>HRReview</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form2" method="post" runat="server">
    <ie:TreeView runat="server" ID="Treeview1" AutoPostBack="True"
    onselectedindexchanged="SelectedIndexChanged">
    <ie:TreeNode Expandable="CheckOnce" Expanded="True" Text="North America"
    TreeNodeSrc="XML/employeetree.xml"></ie:TreeNode>
    </ie:TreeView>
    <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 400px; POSITION:
    absolute; TOP: 32px" runat="server"
    Width="232px" Height="80px">Label</asp:Label>
    </form>
    </body>
    </HTML>
    ===================================================================

    Then I add some code to my 'code-behind' so it looks like this:
    ===================================================================
    Imports System.Data.SqlClient
    Imports Microsoft.Web.UI.WebControls
    Public Class WebForm1
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Treeview1 As Microsoft.Web.UI.WebControls.TreeView

    'NOTE: The following placeholder declaration is required by the Web Form
    Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    End Sub
    Public Sub SelectedIndexChanged(ByVal sender As Object, ByVal e As
    TreeViewSelectEventArgs)
    Label1.Text =
    Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex.ToString).Text
    End Sub
    End Class
    ===================================================================

    When I run it, it shows the XML data fine, but will not get to the
    SelectedIndexChanged procedure (which I have a stop set on)

    Also: Can I add "key" elements to the XML file data to get key values into
    the control? Or is there another way to pass index/key values that can be
    passed when the user clicks on the control?

    I hope this all helps. My deadline to get this done is by the end of the
    month... so I still have a little time. :)

    Scott


    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Schoo,
    >
    > Thanks for your feedback.
    > I feel strange that this event does not fire. I have tried your html code,
    > and added a breakpoint in SelectedIndexChange event handler.
    > This event does fire.
    >
    > In my test I have removed all your xml related code and image url setting
    > code.
    > So I recommand you create a new empty project, then add a treeview control
    > onto the web form, then add the selecteditemchange event handler for it.
    > Then add a breakpoint in your selecteditemchange event handler to

    determine
    > if this event fires.
    >
    > If it really does not fire, you can try to create a new C# project do the
    > same thing, to determine it this strange behavior happens again.
    >
    > At last, if it does not fire, I think you can provide me your project to
    > reproduce this problem for me. I will try my best to help you.
    >
    > ===============================================================
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Schoo, Jan 23, 2004
    #8
  9. Schoo

    Schoo Guest

    Once you told me to open the combo boxes to build the procedure I had a good
    feeling about getting this right and sure enough, once I did that everything
    worked fine. I hand-typed in the procedure code from an example which was
    not good enough. Now it works fine. Thank you.

    Now that I have the procedure firing, is there a way to link a 'key' to the
    tree control? I am basically making a company tree of employees and each
    employee has an associated ID number in the database. I can easily dump
    this to an XML file but I would like to show the names and pass the ID
    number. Here is a sample of my XML file:

    <TREENODES>
    <treenode text = "Joe Blow"
    </treenode>
    <treenode text = "Jane Doe"
    </treenode>
    </TREENODES>

    Can I just add in a 'key' element or something? What code should I write in
    my 'index changed' procedure to return the key from the item?

    Thank you for getting me this far, I hope you can help me with this
    additional issue.

    Schoo

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:0rMY8G$...
    >
    > Hi Schoo,
    >
    > Thanks for your feedback.
    >
    > To resolve your problem, I think the first thing you should do is create a
    > new project WITHOUT any other extra operation(Do not add the xml source),
    > just add several treeview nodes in the IDE.
    >
    > Then handle the treeview's SelectedIndexChanged event. You can try to
    > handle this event through 2 ways: 1.use onselectedindexchanged in html
    > view. 2. Use IDE's to add event handler.
    >
    > To use IDE to add SelectedIndexChanged event handler, you should:
    > 1. Open the code behind page(WebForm1.aspx.vb)
    > 2. In the left top combobox of code editor, choose TreeView1 control
    > 3. In the right top combobox of code editor, choose SelectedIndexChanged
    > event.
    >
    > This will add the SelectedIndexChanged event handler in code behind.
    >
    > I have attached a test project in this post, you can try to see if it
    > works. If it still does not work, please zip your reproduce project to me,
    > I will try to reproduce this out on my side.
    >
    > I am looking forward your further feedback. thanks
    >
    > ==========================================================
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    Schoo, Jan 26, 2004
    #9
  10. Hi Schoo,

    I am glad it finally works, :)

    For your further concern, I think you should refer to TreeNode's NodeData
    property. It gives you a place to store node specific data.
    So you can do like this:
    Private Sub TreeView1_SelectedIndexChange(ByVal sender As Object, ByVal
    e As Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs) Handles
    TreeView1.SelectedIndexChange
    Dim tn As TreeNode =
    TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex)
    Response.Write(tn.NodeData)
    End Sub

    For document reference about TreeView control, please refer to:
    http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/refe
    rence/treeview_entry.asp

    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.
    Have a nice day!!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 27, 2004
    #10
  11. Schoo

    Schoo Guest

    Thank you for the information. I will be sure to research what you
    mentioned.

    Now that I have this working I have a problem I didn't anticipate: because
    the tree can be expanded so large (tall), it is causing a problem on the
    screen. I need the control to be restricted in height and allow the user to
    vertically scroll the items (much like the tree in file explorer). I have
    been playing with CSS to try to create a container to do this but so far not
    having any luck. I have also been playing with frames but this causes other
    issues. Is there a way to limit the control vertically and allow the user
    to scroll the control?

    Schoo

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Schoo,
    >
    > I am glad it finally works, :)
    >
    > For your further concern, I think you should refer to TreeNode's NodeData
    > property. It gives you a place to store node specific data.
    > So you can do like this:
    > Private Sub TreeView1_SelectedIndexChange(ByVal sender As Object,

    ByVal
    > e As Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs) Handles
    > TreeView1.SelectedIndexChange
    > Dim tn As TreeNode =
    > TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex)
    > Response.Write(tn.NodeData)
    > End Sub
    >
    > For document reference about TreeView control, please refer to:
    >

    http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/refe
    > rence/treeview_entry.asp
    >
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    > Have a nice day!!
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Schoo, Jan 27, 2004
    #11
  12. Schoo

    Schoo Guest

    Nevermind... I set the treeview property 'width' and 'height' to values and
    I see that it does restrict it the way I wanted.

    Is there a page on msdn that shows the properties of this control? ie.
    <ie:treeview item1="setting" item2="setting".... n... >

    I am looking for documentation on the 'items' above. Unlike other controls
    in VS.NET, these are not automatically coming up as I type (intellitype).

    Schoo


    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Schoo,
    >
    > I am glad it finally works, :)
    >
    > For your further concern, I think you should refer to TreeNode's NodeData
    > property. It gives you a place to store node specific data.
    > So you can do like this:
    > Private Sub TreeView1_SelectedIndexChange(ByVal sender As Object,

    ByVal
    > e As Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs) Handles
    > TreeView1.SelectedIndexChange
    > Dim tn As TreeNode =
    > TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex)
    > Response.Write(tn.NodeData)
    > End Sub
    >
    > For document reference about TreeView control, please refer to:
    >

    http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/refe
    > rence/treeview_entry.asp
    >
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    > Have a nice day!!
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Schoo, Jan 27, 2004
    #12
  13. Schoo

    Schoo Guest

    I modified my XML file so that I have an extra attribute in the elements
    now:

    <treenode text="Joe Blow" idEmp="12345">

    I did this after looking closely at the "About the TreeView WebControl" at
    msdn, but I don't see how you relay this value to the procedure. I guess I
    am looking for something like this:

    label1.text = Treeview1.GetNodeFromIndex(Treeview1.SelectedNode("idEmp"))

    The above line doesn't work of course, but that is what I am thinking...
    sorry... I'm a ADO guy and I think that way out of habit! It seems like I
    am thinking of this in the wrong way.

    The msdn explaination also makes it look like I might have to write XSL to
    identify the attribute as a node ("Data Binding with XML and XSL Templates"
    section). Is that necessary?

    An example would be great!

    Schoo


    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Schoo,
    >
    > I am glad it finally works, :)
    >
    > For your further concern, I think you should refer to TreeNode's NodeData
    > property. It gives you a place to store node specific data.
    > So you can do like this:
    > Private Sub TreeView1_SelectedIndexChange(ByVal sender As Object,

    ByVal
    > e As Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs) Handles
    > TreeView1.SelectedIndexChange
    > Dim tn As TreeNode =
    > TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex)
    > Response.Write(tn.NodeData)
    > End Sub
    >
    > For document reference about TreeView control, please refer to:
    >

    http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/refe
    > rence/treeview_entry.asp
    >
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    > Have a nice day!!
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Schoo, Jan 27, 2004
    #13
  14. Hi Schoo,

    Thanks for your feedback.

    I have seen 3 posts of you, based on the time you posted, I think you have
    figured out some of the problems yourself.

    I suppose your now conern is the "popup code helper document" in HTML
    desinger in Visual Studio.Net for treeview control.
    =========================================================
    Actually, the "popup code helper document" in Visual Studio.Net is called
    "intellisense", which is a powerful design-time support in Visual
    Studio.Net.
    Noramlly, in code editor the design-time intellisense support is available,
    but in HTML view desinger, you will find the treeview control's
    intellisense is un-available.

    The html designer intellisense is supported through XML schema. All the
    server controls' intellisense supports is stored in C:\Program
    Files\Microsoft Visual Studio .NET\Common7\Packages\schemas\xml\asp.xsd

    To add your own design-time support for treeview control, you should write
    the schema yourself.

    For more information about customize html intellisense support, please
    refer to the article below:
    http://www.bluevisionsoftware.com/WebSite/TipsAndTricksDetails.aspx?Name=Web
    FormsIntellisense

    =========================================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.
    Have a nice day!!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 28, 2004
    #14
  15. Schoo

    Schoo Guest

    Jeffrey,

    Thank you for your reply. I will take a look at writing that code to do the
    intellisense feature. Could you please take a look at the string that talks
    about passing a key/index value through the prodcedure? This is the last
    piece I need to finish this project.

    I also started a new thread in this newsgroup with that specific topic.

    Thanks,

    Scott

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Schoo,
    >
    > Thanks for your feedback.
    >
    > I have seen 3 posts of you, based on the time you posted, I think you have
    > figured out some of the problems yourself.
    >
    > I suppose your now conern is the "popup code helper document" in HTML
    > desinger in Visual Studio.Net for treeview control.
    > =========================================================
    > Actually, the "popup code helper document" in Visual Studio.Net is called
    > "intellisense", which is a powerful design-time support in Visual
    > Studio.Net.
    > Noramlly, in code editor the design-time intellisense support is

    available,
    > but in HTML view desinger, you will find the treeview control's
    > intellisense is un-available.
    >
    > The html designer intellisense is supported through XML schema. All the
    > server controls' intellisense supports is stored in C:\Program
    > Files\Microsoft Visual Studio .NET\Common7\Packages\schemas\xml\asp.xsd
    >
    > To add your own design-time support for treeview control, you should write
    > the schema yourself.
    >
    > For more information about customize html intellisense support, please
    > refer to the article below:
    >

    http://www.bluevisionsoftware.com/WebSite/TipsAndTricksDetails.aspx?Name=Web
    > FormsIntellisense
    >
    > =========================================================
    > Please apply my suggestion above and let me know if it helps resolve your
    > problem.
    >
    > Thank you for your patience and cooperation. If you have any questions or
    > concerns, please feel free to post it in the group. I am standing by to be
    > of assistance.
    > Have a nice day!!
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Schoo, Jan 28, 2004
    #15
  16. Hi Schoo,

    Thanks for your feedback.

    For your further concern, I have found your new post, I will follow up
    there to help you.

    Thanks

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 29, 2004
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,451
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. abargaddon
    Replies:
    0
    Views:
    1,050
    abargaddon
    Jan 17, 2008
  3. Per Salmi

    TreeView not rendering nodes? Cacheing of a TreeView

    Per Salmi, Oct 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    459
    Steve Drake
    Oct 15, 2003
  4. Ionutz
    Replies:
    2
    Views:
    528
    Ionutz
    Oct 23, 2005
  5. stepkurt

    Microsoft Treeview vs System Treeview

    stepkurt, Aug 29, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    373
    Teemu Keiski
    Sep 2, 2007
Loading...

Share This Page