标题:如何解决TreeView运行时遇到的一个错误:*不可访问,因为它受保护级别限制
只看楼主
foshan
Rank: 1
等 级:新手上路
威 望:2
帖 子:605
专家分:0
注 册:2006-3-1
结帖率:100%
 问题点数:0 回复次数:1 
如何解决TreeView运行时遇到的一个错误:*不可访问,因为它受保护级别限制

从网上抄了一段关于 Asp.net 2.0 Treeview 无限级无刷新示例 的代码,运行时出错(红色代码部分为出错的原因),请问大家应该如何解决啊?


错误 1 “_Default.Treeview1_TreeNodePopulate(object, System.Web.UI.WebControls.TreeNodeEventArgs)”不可访问,因为它受保护级别限制 D:\myweb\TreeView\Default.aspx 12


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body bgcolor="white">
<form id="form1" runat="server">
<div>
<asp:treeview ID="Treeview1" runat="server" ImageSet="XPFileExplorer" AutoGenerateDataBindings="false" ExpandDepth=0
OnTreeNodePopulate="Treeview1_TreeNodePopulate"
>
<SelectedNodeStyle BackColor="#B5B5B5"></SelectedNodeStyle>
<Nodes>
<asp:TreeNode Value="C:" Text="C:" PopulateOnDemand="true" SelectAction="Select" NavigateUrl="#" >
</asp:TreeNode>
</Nodes>
<NodeStyle VerticalPadding="2" Font-Names="Tahoma" Font-Size="8pt" HorizontalPadding="2"
ForeColor="Black"></NodeStyle>
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA"></HoverNodeStyle>
</asp:treeview>
</div>
</form>
</body>
</html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
void Treeview1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
if (IsCallback)
if (e.Node.ChildNodes.Count == 0)
{
LoadChildNode(e.Node);
}

}
private void LoadChildNode(TreeNode node)
{

DirectoryInfo directory;
directory = new DirectoryInfo(node.Value);
foreach (DirectoryInfo sub in directory.GetDirectories())
{

TreeNode subNode = new TreeNode(sub.Name);
subNode.Value = sub.FullName;
try
{
if (sub.GetDirectories().Length > 0 || sub.GetFiles().Length > 0)
{
subNode.SelectAction = TreeNodeSelectAction.SelectExpand;
subNode.PopulateOnDemand = true;
subNode.NavigateUrl = "#";
}
}
catch { subNode.ImageUrl = "WebResource.axd?a=s&r=TreeView_XP_Explorer_ParentNode.gif&t=632242003305625000"; }
node.ChildNodes.Add(subNode);

}
foreach (FileInfo fi in directory.GetFiles())
{
TreeNode subNode = new TreeNode(fi.Name);
node.ChildNodes.Add(subNode);
}
}

}

搜索更多相关主题的帖子: TreeView 级别 运行 访问 
2007-03-23 16:03
foshan
Rank: 1
等 级:新手上路
威 望:2
帖 子:605
专家分:0
注 册:2006-3-1
得分:0 
还有一个问题,以上的代码实现 点击TreeView控件的节点页面无刷新 功能是通过什么代码来实现的???

我是2.0超级菜鸟,请多多教导!
2007-03-23 16:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-126172-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.457938 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved