Hello friends, I am trying to approach a procedure but i am stock trying to add a DropDownList control into a TreeView Control, there is no TreeNode.Control.Add(). can somebody give an idea how can i go for this.

thanks.

can't you use TreeView.Controls.Add() method ? becuase Treeview has controls collection.

===========================================================================================

Hello friends, I am trying to approach a procedure but i am stock trying to add a DropDownList control into a TreeView Control, there is no TreeNode.Control.Add(). can somebody give an idea how can i go for this.

thanks.

why dnt you grab the whole data from Dropdown and then Bind to Treeview..

hope it has the same effect and also offers you more control while assigning parent and child elements.

To answer rohand, thanks for your reply. I try to do what you said, first i want to add the dropdown at the treenode levels, second you are right treeview has controls collection but if i try to add a new control it said this "'System.Web.UI.WebControls.TreeView' does not allow child controls.".

dnanetwork i am not sure what is what you want me to do.

to re example my issue this is the scenario imagine having a bill of material which to make one part you need maybe one or multiple parts.


Part1
Part1a "at this level i would like to show a dropdown, showing how the part can be built, even purchase or assembly it"
Part1b
Part2
Part2a

still possible through myway..!

ohhh you mean like making the options checkboxes instead of dropdown within the treeview?

i'm not sure if you are loking for this o/p
but the way you have described your data...
i just fill things up..
in Design page Add Dropdown and manually add values..

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            foreach (var i in DropDownList1.Items)
            {
                TreeNode node = new TreeNode(); // Loading Parent
                node.Text = i.ToString();
                node.PopulateOnDemand = true;
                node.CollapseAll();
                TreeView1.Nodes.Add(node);
            }
        }
      
    }

    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e) // Loading Child..
    {
        // Debug to get more Idea
      TreeNode node = new TreeNode();
      node.Text = e.Node.Text + "a"; // Here you can add your Items through function 
      e.Node.ChildNodes.Add(node); // In this case i've manually added..
    
    }

i hope this is your expected o/p

I have been playing with your first link, no results so far, maybe the fact i am programming asp.net in to windows application is giving me trouble.

the second link will always helpful if i decide to buy telerik controls.

but yes what i want to accomplish is http://www.codeproject.com/KB/tree/DropDownTreeView.aspx but in a web environment.

ok i got one more ...this is kinda funny and long way to go.. (May be u wont like it)
it is called as fooling around with DOT NET... :)
i've tested this it works like a charm..

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            foreach (var i in DropDownList1.Items)
            {
                TreeNode node = new TreeNode(); // Loading Parent
                node.Text = i.ToString();
                node.PopulateOnDemand = true;
                node.CollapseAll();
                TreeView1.Nodes.Add(node);
                
            }
        }
      
    }

    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e) // Loading Child..
    {
        // Debug to get more Idea
      TreeNode node = new TreeNode();
      node.SelectAction = TreeNodeSelectAction.None;
      node.Text = "<select id='Select1' name='D1'><option>one</option><option>two</option><option>Three</option><option>Four</option></select>"; // Here you can add your Items through function 
      e.Node.ChildNodes.Add(node); // In this case i've manually added..
    
    }

ASPX Code...

<form id="form1" runat="server">
    <div>
       
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
        </asp:DropDownList>
        <asp:TreeView ID="TreeView1" runat="server" 
            ontreenodepopulate="TreeView1_TreeNodePopulate" ShowLines="True">
        </asp:TreeView>
       
    </div>
    </form>

Hope that helps !

No problem. If i find something interesting i let you guys know. thanks for your help.

you can also use Literal control for reducing HeadAche...

Refer to my previous post.

You know, that might work, i could get what i want. Now i have my part and my dropdownlist in the same row, I need a button that when pressed, go thru each node and get me the part and the value selected from the dropdown.

you can place button along with that and also add add javascript which will do
your part and use Ajax Update Panel in order to remove postback..

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Page.IsPostBack = False Then
For i As Integer = 1 To DropDownList1.Items.Count
Dim tree As New TreeNode
tree.Text = i.ToString
tree.PopulateOnDemand = True
tree.CollapseAll()
TreeView1.Nodes.Add(tree)
Next
End If
End Sub


Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate

Dim node As New TreeNode
node.Text = e.Node.Text + "a"
e.Node.ChildNodes.Add(node)
End Sub
End Class

hope this helps

KOUROSH NIKZAD

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
For i As Integer = 1 To DropDownList1.Items.Count
Dim tree As New TreeNode
tree.Text = i.ToString
tree.PopulateOnDemand = True
tree.CollapseAll()
TreeView1.Nodes.Add(tree)
Next
End If
End Sub


Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate

Dim node As New TreeNode
node.Text = e.Node.Text + "a"
e.Node.ChildNodes.Add(node)
End Sub
End Class

i made the same mistake twice...

problem statement is ...add dropdownlist control as a child in Treeview control..

wot do u think..Mr. kouroshnik!

I really appreciate the help guys!!!. I am happy with the solution given by dnanetwork adding the dropdownlist in the fly refer above. he recommend me to put a button along the dropdownlist too in order to retrieve the selected item, but actually i would like to have just one update button to go thru the treeview and find selected item in the dropdowlist and the node text. i guess its better to open a new thread for this question?

create edit button beside treenode in asp.net webapplication project with c# codings

how to create edit button beside treenode
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.