自定义 TreeNode 和 SelectNodeChanged
我正在开发 asp.net,并且编写了一个自定义 TreeNode (customTreeNode),用于填充 TreeView。
当触发 selectnodechanged 事件时出现问题,该事件给我一个 TreeNode 对象而不是 customTreeNode 。 我似乎也无法投射它。
以下是我填充树的方式:
node.ChildNodes.Add
(
customTreeNode = new customTreeNode(site)
);
我的 customTreeNode 类:
public class customTreeNode : TreeNode
{
public Guid Id { get; set; }
private SPWebEntry _dataContext;
public SPWebEntry DataContext
{
get
{
return _dataContext;
}
}
public customTreeNode(SPWebEntry DataContext)
{
_dataContext = DataContext;
this.Text = _dataContext.Title;
this.Id = _dataContext.Id;
}
}
并且事件
void treeViewSiteCollection_SelectedNodeChanged(object sender, EventArgs e)
{
treeViewSiteCollection.SelectedNode;
}
treeViewSiteCollection.SelectedNode
是 TreeNode 类型,我无法转换它。
I'm working on asp.net and I've written a custom TreeNode (customTreeNode) that I use to populate a TreeView.
The problem comes up when firing the selectnodechanged event which gives me a TreeNode object and not a customTreeNode. I also cannot seem to cast it.
Here is how I populate my tree:
node.ChildNodes.Add
(
customTreeNode = new customTreeNode(site)
);
My customTreeNode class:
public class customTreeNode : TreeNode
{
public Guid Id { get; set; }
private SPWebEntry _dataContext;
public SPWebEntry DataContext
{
get
{
return _dataContext;
}
}
public customTreeNode(SPWebEntry DataContext)
{
_dataContext = DataContext;
this.Text = _dataContext.Title;
this.Id = _dataContext.Id;
}
}
and the event
void treeViewSiteCollection_SelectedNodeChanged(object sender, EventArgs e)
{
treeViewSiteCollection.SelectedNode;
}
treeViewSiteCollection.SelectedNode
is of type TreeNode and I cannot cast it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须扩展树本身
检查这个帖子
http://forums.asp.net/p/1109208/1713613.aspx# 1713613
You must extend the tree itself also
check this post
http://forums.asp.net/p/1109208/1713613.aspx#1713613