andy

andy

  • NA
  • 10
  • 0

microsoft treeview vs asp.net treeview

Jan 8 2010 5:46 PM

My treeview looks like below
ItemGrpA
  item1
  item2
  item3
ItemGrpB
  item18
  item20
Everything working fine with Microsoft.Web.UI.WebControls treeview control.
Now we want to use the  System.Web.UI.WebControls (asp:TreeView) insteadof microsoft control.
But here its not allowing me to add the node to treenode control. ( showing syntax error here in my code ti.Nodes.Add(tn) )
So how to add a node to a treenode?
 
My code
 
 private void expandtree(DataSet ds)
        {
            XmlDocument objDoc = new XmlDocument();
          
            try
            {
               
                for (int iRow = 0; iRow < ds.Tables[0].Rows.Count; iRow++)
                {
                    DataRow dr = ds.Tables[0].Rows[iRow];
                    if (dr["i_level"].ToString() == "0")
                    {
                        Microsoft.Web.UI.WebControls.TreeNode tn = new Microsoft.Web.UI.WebControls.TreeNode();
                        tn.Text = dr["c_item"].ToString();
                        tn.NodeData = dr["id_item"].ToString();
                        GetChildreninbound(int.Parse(dr["i_level"].ToString()), ds, iRow + 1, tn);
                        TreeView11.Nodes.Add(tn);
                    }
                }
                TreeView11.ExpandLevel = 2;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void GetChildreninbound(int id, DataSet ds, int iRowStart, Microsoft.Web.UI.WebControls.TreeNode ti)
        {
            for (int iRow = iRowStart; iRow < ds.Tables[0].Rows.Count; iRow++)
            {
                DataRow dr = ds.Tables[0].Rows[iRow];
                if (ti.NodeData == dr["id_parent"].ToString())
                {
                    Microsoft.Web.UI.WebControls.TreeNode tn = new Microsoft.Web.UI.WebControls.TreeNode();
                   
                    tn.NodeData = dr["id_item"].ToString();
                  
                     tn.Text = dr["c_item"].ToString();
                  
                    GetChildreninbound(int.Parse(dr["i_level"].ToString()), ds, iRow + 1, tn);
                     
                   

ti.Nodes.Add(tn);//showing syntax error here
                }
                if (int.Parse(dr["i_level"].ToString()) < id)
                {
                    return;
                }
            }
        }