0

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.

5
Contributors
18
Replies
29
Views
7 Years
Discussion Span
Last Post by benny300
Featured Replies
  • 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.. [CODE] protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { foreach … Read More

0

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.

0

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.

0

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

Edited by jbisono: n/a

0

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

0

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

1

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 !

Edited by dnanetwork: n/a

0

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

0

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

Refer to my previous post.

Edited by dnanetwork: n/a

0

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.

0

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..

0

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

0

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

0

i made the same mistake twice...

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

wot do u think..Mr. kouroshnik!

0

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?

0

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

how to create edit button beside treenode

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.