when i click on the treeview the page gets refresh and the control wont go to roottree_SelectedNodeChanged

Plz anyone help me......

/* Document */
    private void GenerateMarksTree(StudentManagement.Student stud)
    {

        TreeView roottree = new TreeView();


        roottree.ForeColor = Color.Black;
        roottree.ShowLines = true;

        TreeNode root = new TreeNode();
        root.Text = stud.Branch.ToString();
        root.Value = "";
        roottree.ShowLines = true;
        roottree.ForeColor = Color.Black;
        roottree.Font.Bold = true;
        roottree.Font.Size = 10;
        roottree.Nodes.Add(root);


        StudentManagement.StudentManagementSoap Service2 = new StudentManagement.StudentManagementSoapClient();
        GetClassDetailsRequest request2 = new GetClassDetailsRequest();
        request2.Body = new GetClassDetailsRequestBody();
        request2.Body.id = stud.StudentId;
        GetClassDetailsResponse response2 = Service2.GetClassDetails(request2);
        foreach (StudentClassDetails studentdetails in response2.Body.GetClassDetailsResult)
        {
            TreeNode childNode = new TreeNode();
            childNode.Value = "";
            childNode.Text = "Semester: " + studentdetails.ClassId.ToString(); //sem.SemistarId.ToString();
            root.ChildNodes.Add(childNode);

            StudentManagement.StudentManagementSoap studentService = new StudentManagement.StudentManagementSoapClient();
            GetExamListRequest studentrequest = new GetExamListRequest();
            studentrequest.Body = new GetExamListRequestBody();
            studentrequest.Body.studentdetails = studentdetails;
            GetExamListResponse studentresponse = studentService.GetExamList(studentrequest);

            foreach (Examination examList in studentresponse.Body.GetExamListResult)
            {

                TreeNode childNode1 = new TreeNode();
                //childNode1.SelectAction = new EventHandler(roottree_SelectedNodeChanged); 
                childNode1.Value = examList.Exam_Id.ToString();
                childNode1.Text = examList.Exam_Name + "" + examList.Start_Date.ToShortDateString();
                childNode.ChildNodes.Add(childNode1);
            }
            childNode.Expanded = false;
        }
        Panelleft1.Controls.Clear();
        Panelleft1.Controls.Add(roottree);
        //roottree.SelectedValue += new EventHandler(roottree_SelectedNodeChanged);
        roottree.SelectedNodeChanged += new EventHandler(roottree_SelectedNodeChanged);

        //roottree.SelectedNodeChanged += new EventHandler(roottree_SelectedNodeChanged);
    }


    protected void roottree_SelectedNodeChanged(object sender, EventArgs e)
    {
        TreeView treeView = (TreeView)sender;
        if (treeView.SelectedValue != null && treeView.SelectedValue != "")
        {
            if (Session["User"] != null)
            {
                User user = (User)Session["User"];
                StudentManagementSoap service = new StudentManagementSoapClient();
                GetMarksListByIdRequest request = new GetMarksListByIdRequest();
                request.Body = new GetMarksListByIdRequestBody();
                request.Body.examId = treeView.SelectedValue;
                request.Body.id = user.TypeOfUserId;
                GetMarksListByIdResponse response = service.GetMarksListById(request);
                DataSet ds = new DataSet("DS");
                DataTable dt = ds.Tables.Add("Result");
                dt.Columns.Add("Subject Name", typeof(string));
                dt.Columns.Add("Maximum Marks", typeof(int));
                dt.Columns.Add("Marks Obtained", typeof(int));
                dt.Columns.Add("Result", typeof(string));

                foreach (Marks mk in response.Body.GetMarksListByIdResult)
                {
                    DataRow dr = dt.NewRow();

                    dr["Subject Name"] = mk.SubjectName.ToString();
                    dr["Maximum Marks"] = int.Parse(mk.MaximumMarks.ToString());
                    dr["Marks Obtained"] = int.Parse(mk.MarksObtained.ToString());
                    dr["Result"] = mk.Result.ToString();

                    dt.Rows.Add(dr);
                }
                GridviewMarks.Font.Bold = true;
                GridviewMarks.Font.Size = 12;
                GridviewMarks.Attributes.Add("Align", "left");

                GridviewMarks.DataSource = ds;
                GridviewMarks.DataBind();


            }
        }
    }

Unfortunately that is a lot of code that we can't compile. Can you upload a sample project with the data embedded?

i tried it my self nd its working, i tried:

TreeView trVw = new TreeView();
        trVw.Nodes.Add(new TreeNode("One"));
        trVw.Nodes.Add(new TreeNode("Two"));
        trVw.SelectedNodeChanged += new EventHandler(trVw_SelectedNodeChanged);
        this.pnl.Controls.Add(trVw);


    void trVw_SelectedNodeChanged(object sender, EventArgs e)
    {
        throw new NotImplementedException();
        //put break point here and it worked
    }

maybe you have a postback event on the control that contains the TreeView try to check it out and if not try to sned me the solution and i will check it for you.

address me in private and i will give you my email

You can check below two things:
1. Check that populate treeview only on load time. Means wrap with !ispostback .
2. Stop running the application open the page in design view check events from property pane that your desired event attached.

This article has been dead for over six months. Start a new discussion instead.