private void bindgrid()
    {
        sqlconn = new SqlConnection(strconn);

        try
        {

            sqlconn.Open();

            // Assigning the RootNode Function to bind the roots
            DataTable dtaddingrootnodes = RootNodes();
            //Declaring the Head Node
            ObClassicTree.ID = "tree123";
            ObClassicTree.NodeDropTargets = "GridPanel";
            ObClassicTree.CssClass = "vista";

            ObClassicTree.EnableDragAndDrop = true;
            Node nodeSuite = new Node();
            // TreeNode headnode = new TreeNode();
            nodeSuite.Text = "Head";
         nodeSuite.AllowDrop = false;
            // Adding the Head Node to the Tree
            ObClassicTree.Nodes.Add(nodeSuite);

            // Looping through the data table to bind the Actual Root Nodes
            for (int i = 0; i < dtaddingrootnodes.Rows.Count; i++)
            {
                Node rootnode = new Node();
               rootnode.AllowDrop = false;
                rootnode.Text = dtaddingrootnodes.Rows[i]["JobCardNo"].ToString();
                rootnode.Value = dtaddingrootnodes.Rows[i]["Jobcard_id"].ToString();
                nodeSuite.ChildNodes.Add(rootnode);

                // Creating a Datatable that will hold the data of actual Child Nodes on the base of the value of rootnode
                DataTable dtactualChildNodes = ChildNodes(Convert.ToString(rootnode.Value));

                //Running a For Loop through the datatable and binding the actual Child Nodes
                for (int j = 0; j < dtactualChildNodes.Rows.Count; j++)
                {
                    //TreeNode rootnode1 = new TreeNode();
                    //rootnode1.Text = dtaddingrootnodes.Rows[j]["complaints"].ToString();
                    //rootnode1.Value = dtaddingrootnodes.Rows[j]["jobcardCompid"].ToString();
                    //rootnode.ChildNodes.Add(rootnode1);

                    Node childnode = new Node();
                   // childnode.AllowDrop = false;
                    childnode.Text = dtactualChildNodes.Rows[j]["complaints"].ToString();
                    childnode.Value = dtactualChildNodes.Rows[j]["jobcardCompid"].ToString();
                    rootnode.ChildNodes.Add(childnode);


                    //  DataTable dtactualChildNodes1 = ChildNodes(Convert.ToString(childnode.Value));


                    DataTable dt = new DataTable();
                    try
                    {
                        sqlconn = new SqlConnection(strconn);
                        sqlconn.Open();
                        // SqlCommand cmd = new SqlCommand("select * from tbl_Employee where employeeId = '" + childnode.Value + "'", sqlconnJobcard_id
                        SqlCommand cmd = new SqlCommand("select  d.designationId,j.JobcardStatus ,e.employeeId,d.designationName,e.employeeName,e.employeeCode from tbl_Employee e,tbl_Designation d,tbl_JobCardAllocation j,tbl_GP_JobcardimationComplaints c where e.designationId=d.designationId and e.employeeId=j.EmployeeId and j.JobCardId=c.Jobcard_id and j.JobcardStatus='active' and  j.JobCardId='" + rootnode.Value + "'", sqlconn);
                        SqlDataAdapter da1 = new SqlDataAdapter();

                        da1.SelectCommand = cmd;
                        da1.Fill(dt);
                    }
                    catch (Exception ex)
                    {
                        string errdesc = ex.Message;
                    }


                    for (int k = 0; k < dt.Rows.Count; k++)
                    {
                        Node childnode1 = new Node();
                        childnode1.Text = dt.Rows[k]["employeeName"].ToString();
                        // childnode1.Text = dt.Rows[k]["employeeCode"].ToString();
                        childnode1.Value = dt.Rows[k]["employeeId"].ToString();
                        childnode.ChildNodes.Add(childnode1);
                        // }
                        //for (int k = 0; k < dt.Rows.Count; k++)
                        //{
                        //for (int l = 0; l < dt.Rows.Count; l++)
                        //{


                            Node childnode2 = new Node();
                            //childnode1.Text = dt.Rows[k]["employeeName"].ToString();
                            childnode2.Text = dt.Rows[k]["designationName"].ToString();
                            childnode2.Value = dt.Rows[k]["employeeId"].ToString();
                            childnode1.ChildNodes.Add(childnode2);
                            //}
                            //for (int k = 0; k < dt.Rows.Count; k++)
                            //{
                            Node childnode3 = new Node();
                            //childnode1.Text = dt.Rows[k]["employeeName"].ToString();
                            childnode3.Text = dt.Rows[k]["employeeCode"].ToString();
                            childnode3.Value = dt.Rows[k]["designationId"].ToString();
                            childnode1.ChildNodes.Add(childnode3);
                       // }
                        // }
                    }
                }

            }
            sqlconn.Close();
        }
        catch (Exception ex)
        {
            string errdesc = ex.Message;
        }
    }


    // Function to get the Data for Root Nodes
    private DataTable RootNodes()
    {
        DataTable dt = new DataTable();
        try
        {
            sqlconn = new SqlConnection(strconn);
            sqlconn.Open();
            SqlCommand cmd = new SqlCommand("select * from tbl_GP_Jobcard", sqlconn);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(dt);
            sqlconn.Close();

        }
        catch (Exception ex)
        {
            string errdesc = ex.Message;
        }
        return dt;
    }


    // Function to bind Actual Child Nodes on the base of the Root Node value
    private DataTable ChildNodes(string RootNode)
    {
        DataTable dt = new DataTable();
        try
        {
            sqlconn = new SqlConnection(strconn);
            sqlconn.Open();
            SqlCommand cmd = new SqlCommand("select * from tbl_GP_JobcardimationComplaints where Jobcard_id = '" + RootNode + "'", sqlconn);
            SqlDataAdapter da1 = new SqlDataAdapter();

            da1.SelectCommand = cmd;
            da1.Fill(dt);

        }
        catch (Exception ex)
        {
            string errdesc = ex.Message;
        }
        return dt;
    }

   protected void ObClassicTree_TreeNodeDrop(object sender, NodeDropEventArgs e)
    {

         string a = e.TargetNode.Text;
        string b = e.SourceNode.Text;
        string fromjobcard = e.SourceNode.Parent.Parent.Text;
        string tojobcard = e.TargetNode.Parent.Text;

        //foreach(TreeNode treenode  in e.SourceNode.ChildNodes)
        //     {

        for (int n = 0; n < e.SourceNode.ChildNodes.Count; n++)
            {
                string i = e.SourceNode.ChildNodes[n].Text;
            }
       // }
         // int k = e.SourceNode.ChildNodes.Count;

        DataTable dt = new DataTable();
        try
        {
            String strConnString = ConfigurationManager.ConnectionStrings["tablesrijConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "TreeviewAddNode";
            cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value = b;
            cmd.Parameters.Add("@empcode", SqlDbType.VarChar).Value = e.SourceNode.ChildNodes[1].Text;
            cmd.Parameters.Add("@desname", SqlDbType.VarChar).Value = e.SourceNode.ChildNodes[0].Text;
            cmd.Parameters.Add("@fromjobcardid", SqlDbType.Int).Value = fromjobcard;
            cmd.Parameters.Add("@tojobcardid", SqlDbType.Int).Value = tojobcard;




            cmd.Connection = con;

                con.Open();
                cmd.ExecuteNonQuery();
               // lblMessage.Text = "Record inserted successfully";


        }
        catch (Exception ex)
        {
            string errdesc = ex.Message;
        }

        bindgrid();

    }

when i run this application it shows the output but after i drag and drop the node to another node in the treeview(using obout ajax ) it shows me that data limit is exceeded.reduce the size of data.what is this exactly.how do i reduce.

Related posts

Recent Viewed