Cant access TreeView Node frm Btn Click event after populating frm another click even

Discussion in '.NET' started by chandrajit_in, Jan 3, 2008.

  1. chandrajit_in

    chandrajit_in

    Joined:
    Jan 3, 2008
    Messages:
    1
    This is very urgent
    I am using Visual Studio 2005, TreeView Control.

    In aspx page only TreeView Control is create. Code is given below:
    ---------------------------------------------------------------------
    <asp:TreeView runat="server" ID="tvUser" Visible="true">
    </asp:TreeView>

    --------------------------------------------------------------------

    Above treeview is populated in a button click event. Code is given below:
    --------------------------------------------------------------------
    private void btnUser_Click(object sender, EventArgs e)
    {
    lblError.Text = string.Empty;
    // Execute Stored Procedure and get Node list as DataTable
    DataTable moTable = UserMapping.GetUserMapping(Convert.ToInt32(dropProcess.SelectedValue),
    Convert.ToInt32(dropTeam.SelectedValue),
    Convert.ToInt32(dropSkillType.SelectedValue),
    Convert.ToInt32(dropSkillLevel.SelectedValue),
    Convert.ToInt32(dropQC.SelectedValue));
    tvUser.Nodes.Clear();
    chlstuser.Items.Clear();
    TreeNode mNode = null;
    // ADD ROOT NODE
    mNode = new TreeNode();
    mNode.Value = dropTeam.SelectedValue + "T";
    mNode.Text = dropTeam.SelectedItem.Text;
    mNode.ToolTip = dropTeam.SelectedItem.Text;
    tvUser.Nodes.Add(mNode);
    // ADD CHILD NODE AND OTHER NODE
    foreach (DataRow moRow in moTable.Rows)
    {
    mNode = new TreeNode();
    mNode.Value = moRow["inID"].ToString();
    mNode.Text = moRow["vcText"].ToString();
    mNode.ToolTip = moRow["vcText"].ToString();
    mNode.Checked = Convert.ToBoolean(moRow["bolChecked"]);

    if ((mNode.Checked))
    {
    ListItem mListItem = new ListItem(moRow["vcText"].ToString(), moRow["inID"].ToString());
    chlstuser.Items.Add(mListItem);
    }
    string mParentKey = moRow["inParentID"].ToString();

    if (mParentKey != "")
    {
    foreach (TreeNode mSearchNode in tvUser.Nodes)
    {
    if (mSearchNode.Value == mParentKey)
    {
    mSearchNode.ChildNodes.Add(mNode);
    break;
    }
    else if (mSearchNode.ChildNodes.Count > 0)
    {
    AddNodeToTree(mSearchNode, mNode, Convert.ToInt32(mParentKey.Trim()));
    }

    }

    }
    }
    }

    public void AddNodeToTree(TreeNode PresentNode, TreeNode NewNode, Int32 ParentID)
    {
    if (Convert.ToInt32(PresentNode.Value) == ParentID)
    {
    PresentNode.ChildNodes.Add(NewNode);
    }
    else
    {
    if (PresentNode.ChildNodes.Count > 0)
    {
    foreach (TreeNode cNode in PresentNode.ChildNodes)
    {
    AddNodeToTree(cNode, NewNode, ParentID);
    }
    }
    else
    {
    if (Convert.ToInt32(PresentNode.Value) == ParentID)
    {
    PresentNode.ChildNodes.Add(NewNode);
    }
    }
    }

    }

    --------------------------------------------------------------------

    Nodes are populated properly.
    After populating the nodes I am trying to access all those nodes in another Button Click event in the same page.

    Relivant code is
    tvUser.Nodes

    But this time TreeView is not returning any of the node which are populated in previous Button Click Event.

    Its showing
    tvUser.Nodes.Count = 0
    Please let me know, under such a scenario, how shall I get access all those nodes.

    Its urgent.... any body please help.
    My mail id is
    chandrajit.samanta 'at' gmail dot com
     
    chandrajit_in, Jan 3, 2008
    #1
    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. wolf
    Replies:
    0
    Views:
    576
  2. viveknatani@gmail.com
    Replies:
    0
    Views:
    1,649
    viveknatani@gmail.com
    Feb 13, 2006
  3. =?Utf-8?B?UEs5?=
    Replies:
    4
    Views:
    3,351
    =?Utf-8?B?UEs5?=
    Mar 6, 2005
  4. Nagaraj
    Replies:
    1
    Views:
    917
    Lionel B
    Mar 1, 2007
  5. F. Da Costa

    frm["custom"] vs frm.getAttribute("custom")?

    F. Da Costa, Jan 30, 2004, in forum: Javascript
    Replies:
    3
    Views:
    137
    F. Da Costa
    Jan 30, 2004
Loading...

Share This Page