Page view counter

Dynamic TreeView control

Rate It (1)

Last post 09-16-2006 4:18 PM by tgoulds. 1 replies.

Sort Posts:

  • Dynamic TreeView control

    09-12-2006, 5:27 PM
    • Loading...
    • tgoulds
    • Joined on 01-05-2006, 9:08 AM
    • Posts 38
    • Points 109

    Hi there group... can any one let me know how i can set the initial node on this dynamic drilldown treeview...

    I have had to set them manualy at the moment... i hold an ObjectID in the session state, which i would like to set as the treeview node value, and i would have to do a search for the Name... (where the ObjectID is the unique field in the database)...

     I have played about and can not work out (or find on google or here) how to do it

     any ideas?

    Thanks inadvance group...

    1    <%@ Control Language="VB" ClassName="TreeView" %>
    2    <%@ Import Namespace="System.Data" %>
    3    <%@ Import Namespace="System.Data.SqlClient" %>
    4    
    5    <script runat="server">
    6        
    7        Dim strConn As String = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
    8            
    9        Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
    10           Dim con As New SqlConnection(strConn)
    11           Dim cmd As New SqlCommand("SELECT * FROM EASObject WHERE ParentID=@ParentID", con)
    12           cmd.Parameters.AddWithValue("@ParentID", e.Node.Value)
    13           con.Open()
    14           Try
    15               Dim dtr As SqlDataReader = cmd.ExecuteReader()
    16               While dtr.Read()
    17                   Dim newNode As New TreeNode()
    18                   newNode.PopulateOnDemand = True
    19                   newNode.Text = dtr("Name").ToString()
    20                   newNode.Value = dtr("ID").ToString()
    21                   e.Node.ChildNodes.Add(newNode)
    22               End While
    23           Finally
    24               con.Close()
    25           End Try
    26           
    27       End Sub
    28   
    29   </script>
    30   
    31      <asp:TreeView
    32           id="TreeView1"
    33           ImageSet="Arrows"
    34           ShowLines="true"
    35           ExpandDepth="1"
    36           OnTreeNodePopulate="TreeView1_TreeNodePopulate" 
    37           Runat="Server" MaxDataBindDepth="-1">
    38           <Nodes>
    39           <asp:TreeNode 
    40               Text="Primavera PM" 
    41               Value="17"
    42               PopulateOnDemand="True" />
    43           </Nodes>
    44       </asp:TreeView>    
    45   
    
     
  • Re: Dynamic TreeView control

    09-16-2006, 4:18 PM
    Answer
    • Loading...
    • tgoulds
    • Joined on 01-05-2006, 9:08 AM
    • Posts 38
    • Points 109

    This has been sorted by setting the value to Zero and then performing a simple if statement.... 

    If e.Node.Value = 0 Then
                e.Node.Value = ObjectID
                e.Node.Text = "Children"
            End If
     

     

Page 1 of 1 (2 items)