今天使用SPHierarchyDataSourceControl和SPTreeView来显示SharePoint文档库层级结构的过程中,发现一直在报下面的错误:
The target 'ctl00$ctl01$mainContentArea$treeNavigation$WebTreeViewV4' for the callback could not be found or did not implement ICallbackEventHandler.
然后就懵逼了,这是问题是在展开左侧导航树的过程中发生的,所以猜想应该是需要实现个什么接口。找了半天似乎没人遇到过,难道这是个别人都会的问题,只是我小白了。
最终花费了宝贵的2小时,终于解决了,不过真的很简单,实现个“INamingContainer”接口就OK,请参考以下代码:
public partial class LeftNavigation : UserControl, INamingContainer
{
protected void Page_Load(object sender, EventArgs e)
{
SPList _list = SPContext.Current.List;
// Setup myDataSource to show only the Child List
SPHierarchyDataSourceControl myDataSource = new SPHierarchyDataSourceControl();
myDataSource.ID = "TreeViewDataSourceV4";
myDataSource.IncludeDiscussionFolders = false;
if (_list != null)
{
myDataSource.RootContextObject = "List";
myDataSource.ShowDocLibChildren = true;
myDataSource.ShowFolderChildren = true;
myDataSource.ShowListChildren = true;
myDataSource.ShowWebChildren = false; }
else
{
myDataSource.RootContextObject = "Web";
myDataSource.ShowDocLibChildren = true;
myDataSource.ShowFolderChildren = true;
myDataSource.ShowListChildren = true;
myDataSource.ShowWebChildren = false;
}
TreeViewNavigationManagerV4.Controls.Add(myDataSource); SPTreeView treeview = new SPTreeView();
treeview.ID = "WebTreeViewV4";
treeview.ShowLines = false;
treeview.DataSourceID = "TreeViewDataSourceV4";
treeview.ExpandDepth = ;
treeview.SelectedNodeStyle.CssClass = "ms-tv-selected";
treeview.NodeStyle.CssClass = "ms-tv-item";
treeview.NodeIndent = ;
treeview.ExpandImageUrl = "/_layouts/15/images/tvclosed.png?rev=23";
treeview.ExpandImageUrlRtl = "/_layouts/15/images/tvclosedrtl.png?rev=23";
treeview.CollapseImageUrl = "/_layouts/15/images/tvopen.png?rev=23";
treeview.CollapseImageUrlRtl = "/_layouts/15/images/tvopenrtl.png?rev=23";
treeview.NoExpandImageUrl = "/_layouts/15/images/tvblank.gif?rev=23";
TreeViewRememberScrollV4.Controls.Add(treeview);
}
}