问题
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