private void FillChild(string index, TreeNode tn)//fill up child nodes and respective child nodes of them { DataTable dt = new DataTable(); dt = GetRackMasterByParentId(index); int i = 0; while (i < dt.Rows.Count) { TreeNode tn1 = new TreeNode(); tn1.Text = dt.Rows[i]["Rack_Name"].ToString(); tn1.Value = dt.Rows[i]["Rack_Id"].ToString(); tn.ChildNodes.Add(tn1); FillChild((dt.Rows[i]["Rack_Id"].ToString()), tn1); i++; } TreeViewRack.DataBind(); }
//To apply tree view, delete options and BIN tab private void BindTreeView()//fucntion to fill up TreeView according to parent child nodes { TreeViewRack.Nodes.Clear(); DataTable dt = new DataTable(); //string x = "ParentRackId=" + "' '" + ""; string x = "ParentRackId=" + "0" + ""; dt = ObjRackMaster.GetRackMasterTrueAll(StrCompId, StrBrandId, strLocationId); 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]["Rack_Name"].ToString(); tn.Value = dt.Rows[i]["Rack_Id"].ToString(); TreeViewRack.Nodes.Add(tn); FillChild((dt.Rows[i]["Rack_Id"].ToString()), tn); i++; } TreeViewRack.DataBind(); }