protected void bindtreeviewMaping()
    {
        try
        {
            this.TreeView2.Nodes.Clear();
            HierarchyTree        hierarchy = new HierarchyTree();
            HierarchyTree.HGroup objhtree  = null;

            string selgroup = "select distinct ITGroupPK,GroupName,ParentCode from IT_GroupMaster where CollegeCode='" + ddlcolload.SelectedItem.Value + "'";
            ds.Clear();
            ds = d2.select_method_wo_parameter(selgroup, "Text");
            this.TreeView2.Nodes.Clear();
            hierarchy.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                objhtree             = new HierarchyTree.HGroup();
                objhtree.group_code  = int.Parse(ds.Tables[0].Rows[i]["ITGroupPK"].ToString());
                objhtree.parent_code = int.Parse(ds.Tables[0].Rows[i]["ParentCode"].ToString());
                objhtree.group_name  = ds.Tables[0].Rows[i]["GroupName"].ToString();
                hierarchy.Add(objhtree);
            }

            foreach (HierarchyTree.HGroup hTree in hierarchy)
            {
                HierarchyTree.HGroup parentNode = hierarchy.Find(delegate(HierarchyTree.HGroup emp) { return(emp.group_code == hTree.parent_code); });
                if (parentNode != null)
                {
                    foreach (TreeNode tn in TreeView2.Nodes)
                    {
                        if (tn.Value == parentNode.group_code.ToString())
                        {
                            tn.ChildNodes.Add(new TreeNode(hTree.group_name.ToString(), hTree.group_code.ToString()));
                        }
                        if (tn.ChildNodes.Count > 0)
                        {
                            foreach (TreeNode ctn in tn.ChildNodes)
                            {
                                RecursiveChild(ctn, parentNode.group_code.ToString(), hTree);
                            }
                        }
                    }
                }
                else
                {
                    TreeView2.Nodes.Add(new TreeNode(hTree.group_name, hTree.group_code.ToString()));
                }
                TreeView2.ExpandAll();
                //TreeView2.ExpandAll();
            }
        }
        catch
        {
        }
    }
    protected void bindtreeview()
    {
        try
        {
            string dt_groupcode  = "";
            string dt_parentcode = "";

            if (collegecode != "")
            {
                this.TreeView1.Nodes.Clear();
                HierarchyTree        hierarchy = new HierarchyTree();
                HierarchyTree.HGroup objhtree  = null;

                string selgroup = "select distinct FinGroupPK,GroupName,ParentCode from FM_FinGroupMaster where CollegeCode='" + ddlcolload.SelectedItem.Value + "'";
                ds.Clear();
                ds = d2.select_method_wo_parameter(selgroup, "Text");
                this.TreeView1.Nodes.Clear();
                hierarchy.Clear();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    objhtree             = new HierarchyTree.HGroup();
                    objhtree.group_code  = int.Parse(ds.Tables[0].Rows[i]["FinGroupPK"].ToString());
                    objhtree.parent_code = int.Parse(ds.Tables[0].Rows[i]["ParentCode"].ToString());
                    objhtree.group_name  = ds.Tables[0].Rows[i]["GroupName"].ToString();
                    hierarchy.Add(objhtree);
                }

                if (ds.Tables[0].Rows.Count > 0)
                {
                    string get_topic_no  = "";
                    string get_topic_no1 = "";
                    string get_topic_no2 = "";

                    for (int dt_row_cnt = 0; dt_row_cnt < ds.Tables[0].Rows.Count; dt_row_cnt++)
                    {
                        dt_groupcode = ds.Tables[0].Rows[dt_row_cnt][0].ToString();
                        string[] split_topics2 = dt_groupcode.Split('/');
                        for (int i = 0; split_topics2.GetUpperBound(0) >= i; i++)
                        {
                            if (get_topic_no == "")
                            {
                                get_topic_no = "'" + split_topics2[i] + "'";
                            }
                            else
                            {
                                get_topic_no = get_topic_no + ',' + "'" + split_topics2[i] + "'";
                            }
                        }
                    }

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        for (int dt_dailyentdet1_row_cnt = 0; dt_dailyentdet1_row_cnt < ds.Tables[0].Rows.Count; dt_dailyentdet1_row_cnt++)
                        {
                            dt_parentcode = ds.Tables[0].Rows[dt_dailyentdet1_row_cnt][1].ToString();
                            string[] split_topics3 = dt_parentcode.Split('/');
                            for (int i = 0; split_topics3.GetUpperBound(0) >= i; i++)
                            {
                                if (get_topic_no1 == "")
                                {
                                    get_topic_no1 = "'" + split_topics3[i] + "'";
                                }
                                else
                                {
                                    get_topic_no1 = get_topic_no1 + ',' + "'" + split_topics3[i] + "'";
                                }
                            }
                        }
                    }
                    if (get_topic_no1 != "")
                    {
                        get_topic_no2 = get_topic_no + "," + get_topic_no1;
                    }
                    else
                    {
                        get_topic_no2 = get_topic_no;
                    }

                    selgroup = "select FinGroupPK,ParentCode,GroupName from FM_FinGroupMaster where convert(varchar,FinGroupPK) in(" + get_topic_no2 + ") and CollegeCode='" + ddlcolload.SelectedItem.Value + "' order by ParentCode,FinGroupPK";
                    DataSet dsloadtopic = d2.select_method_wo_parameter(selgroup, "Text");
                    if (dsloadtopic.Tables[0].Rows.Count > 0)
                    {
                        hierarchy.Clear();

                        for (int at = 0; at < dsloadtopic.Tables[0].Rows.Count; at++)
                        {
                            string sqlquery    = "select isnull(count(*),0) as ischild from FM_FinGroupMaster where ParentCode=" + dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString() + " and CollegeCode='" + ddlcolload.SelectedItem.Value + "'";
                            string ischild     = d2.GetFunction(sqlquery);
                            string sqlquery1   = "select isnull(count(*),0) as isavailable from FM_FinGroupMaster where convert(varchar,FinGroupPK) in(" + get_topic_no2 + ") and ParentCode=" + dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString() + " and CollegeCode='" + ddlcolload.SelectedItem.Value + "'";
                            string isavailable = d2.GetFunction(sqlquery1);

                            if (Convert.ToInt16(ischild) == 0)
                            {
                                objhtree             = new HierarchyTree.HGroup();
                                objhtree.group_code  = int.Parse(dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString());
                                objhtree.parent_code = int.Parse(dsloadtopic.Tables[0].Rows[at]["ParentCode"].ToString());
                                objhtree.group_name  = dsloadtopic.Tables[0].Rows[at]["GroupName"].ToString();
                                hierarchy.Add(objhtree);
                            }
                            else if (Convert.ToInt16(ischild) > 0 && Convert.ToInt16(isavailable) > 0)
                            {
                                objhtree             = new HierarchyTree.HGroup();
                                objhtree.group_code  = int.Parse(dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString());
                                objhtree.parent_code = int.Parse(dsloadtopic.Tables[0].Rows[at]["ParentCode"].ToString());
                                objhtree.group_name  = dsloadtopic.Tables[0].Rows[at]["GroupName"].ToString();
                                hierarchy.Add(objhtree);
                            }
                        }
                    }

                    panel3.Visible = true;
                }

                foreach (HierarchyTree.HGroup hTree in hierarchy)
                {
                    HierarchyTree.HGroup parentNode = hierarchy.Find(delegate(HierarchyTree.HGroup emp) { return(emp.group_code == hTree.parent_code); });
                    if (parentNode != null)
                    {
                        foreach (TreeNode tn in TreeView1.Nodes)
                        {
                            if (tn.Value == parentNode.group_code.ToString())
                            {
                                tn.ChildNodes.Add(new TreeNode(hTree.group_name.ToString(), hTree.group_code.ToString()));
                            }
                            if (tn.ChildNodes.Count > 0)
                            {
                                foreach (TreeNode ctn in tn.ChildNodes)
                                {
                                    RecursiveChild(ctn, parentNode.group_code.ToString(), hTree);
                                }
                            }
                        }
                    }
                    else
                    {
                        TreeView1.Nodes.Add(new TreeNode(hTree.group_name, hTree.group_code.ToString()));
                    }

                    TreeView1.ExpandAll();
                }

                //if (TreeView1.Nodes.Count < 1)
                //{

                //    //BtnNewTree.Enabled = false;
                //}
                //else
                //{
                //    //BtnNewTree.Enabled = true;
                //}
            }
        }
        catch
        {
        }
    }