Tree View Update PostBack

纵然是瞬间 提交于 2019-12-12 03:19:32

问题


I did a file system like, with a tree view, and when I click on a node I can see the files inside this node.

I have a problem now ... When I click on a node I display the files but when I click on this same node , the files disapear .

This is a part of my code, PageLoad and also TreeViewLoad .

   protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.Cookies["UserSettings"] == null))
        {
            Response.Redirect("Logon.aspx");
        }
    }

    #region TreeView

    protected void MyTreeView_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int userid = Convert.ToInt32(Request.Cookies["UserSettings"]["Id"]);
            DbHelper Db = new DbHelper();

            root = Db.GetFoldersForUser(userid);

            TreeNode rootTreeView = new TreeNode("Projects");
            rootTreeView = LoadNodes(root.TopFolders, rootTreeView);

            MyTreeView.Nodes.Add(rootTreeView);
            MyTreeView.CollapseAll();

        }
    }

    #endregion

I'm fed up because I really can't find the solution . Is it a problem of !Postback ? If someone has the solution please help me .

KR


回答1:


it because of you are populating the tree view dynamically . and on post back you are not instantiating it what else you can do is.

1)put above code in page_init . 2) fill the tree view in the way your doing.

Or

reomve the

    if (!IsPostBack) 


来源:https://stackoverflow.com/questions/7837015/tree-view-update-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!