树状图更新回发 [英] Tree View Update PostBack
问题描述
我做了一个树状的文件系统,当我单击一个节点时,我可以看到该节点中的文件.
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 .
这是我的代码PageLoad和TreeViewLoad的一部分.
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
推荐答案
它是因为您正在动态填充树视图.在回发时,您没有实例化它您还可以做些什么.
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)将以上代码放在page_init中.2)按照您的操作方式填充树形视图.
1)put above code in page_init . 2) fill the tree view in the way your doing.
或
删除
if (!IsPostBack)
这篇关于树状图更新回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!