private void FillChild(string index, TreeNode tn)//fill up child nodes and respective child nodes of them { DataTable dt = new DataTable(); dt = GetProductCategoryByParentId(index); int i = 0; while (i < dt.Rows.Count) { TreeNode tn1 = new TreeNode(); tn1.Text = dt.Rows[i]["Category_Name"].ToString(); tn1.Value = dt.Rows[i]["Category_Id"].ToString(); tn.ChildNodes.Add(tn1); FillChild((dt.Rows[i]["Category_Id"].ToString()), tn1); i++; } TreeViewCategory.DataBind(); }
//To apply tree view, delete options and BIN tab private void BindTreeView()//fucntion to fill up TreeView according to parent child nodes { TreeViewCategory.Nodes.Clear(); DataTable dt = new DataTable(); string x = "Parent_Id=" + "' '" + ""; dt = ObjProductCateMaster.GetProductCategoryTrueAllData(StrCompId); dt = new DataView(dt, x, "", DataViewRowState.OriginalRows).ToTable(); int i = 0; while (i < dt.Rows.Count) { TreeNode tn = new TreeNode(); tn.Text = dt.Rows[i]["Category_Name"].ToString(); tn.Value = dt.Rows[i]["Category_Id"].ToString(); TreeViewCategory.Nodes.Add(tn); FillChild((dt.Rows[i]["Category_Id"].ToString()), tn); i++; } TreeViewCategory.DataBind(); }