[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

Select TreeView Checkboxes (Multiple levels)

I've managed to populate the TreeView to a Node Depth of 4. I folloewd the official MSDN example (This is the first time I've ever used this control). Users will select and save multiple Companies, Divisions and Departments (Code I must still try to write). What I'm trying to do now is display the selected Areas in the TreeView when the Page loads so users can see their persisted changes.
 protected void PopulateNode(Object sender, TreeNodeEventArgs e)
    {
        // Call the appropriate method to populate a node at a particular level.
        switch (e.Node.Depth)
        {
            case 0:// Company
                PopulateCompany(e.Node);//1
                break;
            case 1:// Division
                PopulateDivision(e.Node);//2
                break;
            case 2:// Department
                PopulateDepartment(e.Node);//3
                break;
        }
    }
What I'm trying to do now, is programatically select the nodes associated checkbox programatically, and it does not seem to reflect the change.
 // (!Page.IsPostBack)Inside the PopulateNode() Event
 StringBuilder sbSQLCompany = new StringBuilder();
            sbSQLCompany.Append("SELECT OH.[CompanyID], D.[Company] FROM [UserDetails_MailReport_Company] AS OH ");
            sbSQLCompany.Append("LEFT OUTER JOIN [Company] AS D ON OH.[CompanyID] = D.[CompanyID] ");
            sbSQLCompany.Append("WHERE OH.[UserID] = @UserID");
            try
            {
                using (SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString))
                {
                    using (SqlCommand cm1 = new SqlCommand(sbSQLCompany.ToString(), cn1))
                    {
                        cm1.Parameters.AddWithValue("@UserID", Membership.GetUser().ProviderUserKey.ToString());
                        cn1.Open();
                        using (SqlDataReader rd = cm1.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (rd.Read())
                            {
                                string s = rd["Company"].ToString();
                                foreach (TreeNode CompanyNode in tvOutHigh.Nodes[0].ChildNodes)
                                {
                                    if (CompanyNode.Depth == 1)
                                    {
                                        if (CompanyNode.Text == rd["Company"].ToString())
                                        {
                                            if (CompanyNode.Value == rd["CompanyID"].ToString())
                                            {
                                                CompanyNode.Selected = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
It finds the node with no problem, but after changing the Node.Selected value to true, it never reflects the change. Am I doing this is the correct event? The TreeView only seems to populate after the page_Load has fired. I'm trying to do this for all node levels.
0
Hornwood
Asked:
Hornwood
1 Solution
 
Kumaraswamy RCommented:
HI

TreeViews-  one that is marked Visible=False and Node Checked = TRUE

http://forums.asp.net/t/1839963.aspx/1?Select+TreeView+Checkboxes+Multiple+levels
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now