0

在点击冷水机节点之前

其他节点也展开

在上面的 2 张图片中,在第 1 张图片中,我展开树视图并单击名为 chillers 的节点。在这里,直到我单击树视图旁边的小箭头,我在 Home.aspx 上。当我单击冷却器节点时,我重定向到其他页面 abcd.aspx。

第二张图片显示,当点击 chillers 时,上述节点也被展开。我猜这是因为回发而发生的。如何解决问题。我也尝试将树视图控件保留在更新面板中。但没有任何帮助。

以下是我的 aspx 代码

<asp:TreeView ID="TreeView_Parent_Child" EnableClientScript="true" align="left"
        AutoGenerateDataBindings="true" LeafNodeStyle-ForeColor="Black" NodeStyle-ForeColor="Black"
        PopulateNodesFromClient="true" runat="server" Font-Names="Arial"
        OnTreeNodePopulate="PopulateNode"
        HoverNodeStyle-BackColor="ActiveBorder" Font-Size="Small" ImageSet="Arrows" NodeStyle-HorizontalPadding="5px">
        <HoverNodeStyle Font-Bold="true" BackColor="Beige" />
        <Nodes>
        </Nodes>
        <NodeStyle ForeColor="Black" />
        <LeafNodeStyle ForeColor="Black" />

    </asp:TreeView>

cs代码:

protected void PopulateNode(object sender, TreeNodeEventArgs e)
{
    try
    {
        string nodevalue = e.Node.Value.ToString();
        nodecount = nodevalue.Count(c => c == '/');

        List<string> abc = new List<string>();           
        int iii = 0;
        if (nodecount == 1)
        {
            string[,] param = new string[2, 2];
            param[0, 0] = "@Folder_Id";
            param[0, 1] = e.Node.Value.Split('/')[0];
            param[1, 0] = "@Login_Id";
            param[1, 1] = Session["USER_ID"].ToString();

            DataSet dsFolders = cbal.fillGrid_with_param("SubFolder_From_Folder_Directory", param);              


            DataRow[] dr_Not_Parts = dsFolders.Tables[0].Select("Subfolder_Code<>6");

            if (dr_Not_Parts.Length > 0)
            {
                for (int i = 0; i < dr_Not_Parts.Length; i++)
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text = dr_Not_Parts[i]["Subfolder_Name"].ToString();
                    newNode.Value = dr_Not_Parts[i]["Subfolder_Code"].ToString() + "/1/1";
                    newNode.PopulateOnDemand = true;

                    newNode.SelectAction = TreeNodeSelectAction.Expand;


                    newNode.NavigateUrl = "Auto_Test.aspx?value=" + newNode.Value + "";
                    newNode.ImageUrl = "~/Images/folderSmall2.jpg";
                    e.Node.ChildNodes.Add(newNode);
                }
            }

            Session["Test"] = "1";
        }
        if (nodecount == 2)
        {
            DataSet ds_rel = cbal.fillGrid("UserID_From_LOGIN_NAME", "@LoginName", Session["USER_ID"].ToString());

            string[,] param = new string[2, 2];
            param[0, 0] = "@empcode";
            param[0, 1] = ds_rel.Tables[0].Rows[0]["CODE"].ToString();

            param[1, 0] = "@SubFolder_Id";
            param[1, 1] = e.Node.Value.Split('/')[0];

            ViewState["collapse"] = e.Node.Value.Split('/')[0];

            DataSet dsFolders = cbal.fillGrid_with_param("MainLevel_From_SubFolder_New", param);

            DataRow[] dr_Not_Parts = dsFolders.Tables[0].Select("MainLevel_Code<>8");

            if (dr_Not_Parts.Length > 0)
            {
                for (int i = 0; i < dr_Not_Parts.Length; i++)
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text = dr_Not_Parts[i]["MainLevel_Name"].ToString();
                    newNode.Value = dr_Not_Parts[i]["MainLevel_Code"].ToString() + "/1/1/1";
                    newNode.PopulateOnDemand = true;

                    newNode.SelectAction = TreeNodeSelectAction.Expand;                        

                    newNode.NavigateUrl = "Auto_Test.aspx?value=" + newNode.Value + "";
                    newNode.ImageUrl = "~/Images/folderSmall2.jpg";

                    e.Node.ChildNodes.Add(newNode);                       
                }
            }

            Session["Test"] = "2";
        }

        if (nodecount == 3)
        {
            string[,] param = new string[2, 2];
            param[0, 0] = "@MainLevel_Id";
            param[0, 1] = e.Node.Value.Split('/')[0];
            param[1, 0] = "@Login_Id";
            param[1, 1] = Session["USER_ID"].ToString();
            ViewState["collapse"] = e.Node.Value.Split('/')[0];
            DataSet dsFolders = cbal.fillGrid_with_param("SubMainLevel_From_MainLevel", param);             

            if (dsFolders.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsFolders.Tables[0].Rows.Count; i++)
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text = dsFolders.Tables[0].Rows[i]["SubMainLevel_Name"].ToString();
                    newNode.Value = dsFolders.Tables[0].Rows[i]["SubMainLevel_ID"].ToString();
                    newNode.PopulateOnDemand = true;                       
                    newNode.SelectAction = TreeNodeSelectAction.Expand;                     

                    newNode.ImageUrl = "~/Images/folderSmall2.jpg";
                }
            }

            Session["Test"] = "3";
        }

        if (nodecount == 4)
        {
            string[,] param = new string[1, 2];
            param[0, 0] = "@SubMainLevel_Id";
            param[0, 1] = e.Node.Value.Split('/')[0];

            DataSet dsFolders = cbal.fillGrid_with_param("Document_View_forFolderClick", param);            


            if (dsFolders.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsFolders.Tables[0].Rows.Count; i++)
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text = dsFolders.Tables[0].Rows[i]["CODE"].ToString();
                    newNode.Value = dsFolders.Tables[0].Rows[i]["Document_Name"].ToString();
                    newNode.PopulateOnDemand = true;                      
                    newNode.SelectAction = TreeNodeSelectAction.Expand;                      


                    newNode.ImageUrl = "~/Images/pdfimg.jpg";

                    e.Node.ChildNodes.Add(newNode);
                }
            }
        }
 }
        catch (Exception ex)
        {

        }
    }

在我从事现场项目时,请帮助我解决任何问题。

4

0 回答 0