TreeView问题!加载出现问题,有时候出现,有时候又不出现!请教高手

jemmy 2003-07-23 12:29:50
The node at index 0.0 is not currently displayed in the tree. SelectedNodeIndex cannot be set to an undisplayed node (all parents of a selected node must be expanded).
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Exception: The node at index 0.0 is not currently displayed in the tree. SelectedNodeIndex cannot be set to an undisplayed node (all parents of a selected node must be expanded).

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[Exception: The node at index 0.0 is not currently displayed in the tree. SelectedNodeIndex cannot be set to an undisplayed node (all parents of a selected node must be expanded).]
Microsoft.Web.UI.WebControls.TreeView.set_SelectedNodeIndex(String value)
Microsoft.Web.UI.WebControls.TreeView.DoSelectedIndexChange(TreeViewSelectEventArgs e)
Microsoft.Web.UI.WebControls.TreeView.ProcessEvents(String eventArg)
Microsoft.Web.UI.WebControls.TreeView.ProcessData(String strData)
Microsoft.Web.UI.WebControls.BasePostBackControl.LoadPostData(String postDataKey, NameValueCollection postCollection)
Microsoft.Web.UI.WebControls.BasePostBackControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
System.Web.UI.Page.ProcessRequestMain()

代码 如下:
/////////////////////////////////////////////////////////
private void show_tree()
{
Microsoft.Web.UI.WebControls.TreeNode rootnode=new Microsoft.Web.UI.WebControls.TreeNode();
rootnode.NodeData=this.rootid.ToString();
rootnode.Text=this.rootname;
rootnode.ImageUrl="images/tree/base.gif";
rootnode.ExpandedImageUrl="images/tree/base.gif";
this.show_tree_ChildNode(rootnode);
this.OrgTree.Nodes.Add(rootnode);
this.treecell.Controls.Add(this.OrgTree);
TreeSet();
}

private int show_tree_ChildNode(Microsoft.Web.UI.WebControls.TreeNode cur)
{
cur.Nodes.Clear();
string sql = "select orgid,orgname from bool_sys_org where parentid="+ cur.NodeData;
Conn getsubnodes=new Conn(sql,"select");
int tncount = 0;
while(getsubnodes.reader.Read())
{
tncount++;
Microsoft.Web.UI.WebControls.TreeNode subnode = new Microsoft.Web.UI.WebControls.TreeNode();
subnode.Text = (getsubnodes.reader.GetValue(1)).ToString();
subnode.NodeData = (getsubnodes.reader.GetValue(0)).ToString() ;
if (show_tree_ChildNode(subnode) > 0)
{
subnode.ExpandedImageUrl = "images/tree/folderopen.gif";
subnode.ImageUrl = "images/tree/folder.gif";
}
else
{
subnode.ImageUrl = "images/tree/folder.gif";
}
cur.Nodes.Add(subnode);
}
getsubnodes.CloseDatabase();
return tncount;
}
...全文
139 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jemmy 2003-07-23
  • 打赏
  • 举报
回复
up
hgknight 2003-07-23
  • 打赏
  • 举报
回复
选中节点0.0时,必须把它的父节点0展开
Expand=true
batisituta 2003-07-23
  • 打赏
  • 举报
回复
节点0.0不在当前树中。
Englishgenius 2003-07-23
  • 打赏
  • 举报
回复
你把 TreeView卸载,重装一边试试
  • 打赏
  • 举报
回复
帮你up!

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧