MSDN Sample AccessSiteMapProvider 不能使TreeView控件工作的解决
来源:互联网 发布:谷歌娘配音软件 编辑:程序博客网 时间:2024/05/18 03:12
在.Net 2.0环境下使用TreeView控件,我想自定义SiteMapProvider。查阅MSDN,有一个例子AccessSiteMapProvider,ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_aspnetcon/html/636e72a1-8bbf-4b1f-bb52-7429c4c90e01.htm
但是该例子有问题,TreeView控件只显示根节点,Menu和SiteMapPath控件可以工作。
检查后发现是BuildSiteMap函数中没有向Provider添加根节点,修改如下:
public override SiteMapNode BuildSiteMap()
{
// Since the SiteMap class is static, make sure that it is
// not modified while the site map is built.
lock (this)
{
// If there is no initialization, this method is being
// called out of order.
if (!IsInitialized)
{
throw new Exception("BuildSiteMap called incorrectly.");
}
// If there is no root node, then there is no site map.
if (null == rootNode)
{
// Start with a clean slate
Clear();
// Select the root node of the site map from Microsoft Access.
int rootNodeId = -1;
if (accessConnection.State == ConnectionState.Closed)
accessConnection.Open();
OleDbCommand rootNodeCommand =
new OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL",
accessConnection);
OleDbDataReader rootNodeReader = rootNodeCommand.ExecuteReader();
if (rootNodeReader.HasRows)
{
rootNodeReader.Read();
rootNodeId = rootNodeReader.GetInt32(0);
// Create a SiteMapNode that references the current StaticSiteMapProvider.
rootNode = new SiteMapNode(this,
rootNodeId.ToString(),
rootNodeReader.GetString(1),
rootNodeReader.GetString(2));
}
else
{
rootNodeReader.Close();
accessConnection.Close();
return null;
}
// Add the node to the site map
AddNode(rootNode, null);
rootNodeReader.Close();
// Select the child nodes of the root node.
OleDbCommand childNodesCommand =
new OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?",
accessConnection);
OleDbParameter rootParam = new OleDbParameter("parentid", OleDbType.Integer);
rootParam.Value = rootNodeId;
childNodesCommand.Parameters.Add(rootParam);
OleDbDataReader childNodesReader = childNodesCommand.ExecuteReader();
if (childNodesReader.HasRows)
{
SiteMapNode childNode = null;
while (childNodesReader.Read())
{
childNode = new SiteMapNode(this,
childNodesReader.GetInt32(0).ToString(),
childNodesReader.GetString(1),
childNodesReader.GetString(2));
// Use the SiteMapNode AddNode method to add
// the SiteMapNode to the ChildNodes collection.
AddNode(childNode, rootNode);
}
}
childNodesReader.Close();
accessConnection.Close();
}
return rootNode;
}
}
- MSDN Sample AccessSiteMapProvider 不能使TreeView控件工作的解决
- 解决TreeView控件不能正常显示的问题
- TreeView控件不能显示图标的问题
- 解决ASP.NET的TREEVIEW控件不能显示树型结构
- 解决ASP.NET的TREEVIEW控件不能显示树型结构
- Winsock MSDN Sample (Server)
- Winsock MSDN Sample (Client)
- MSDN DOM sample
- TreeView控件在IE7不能正常显示
- 控件treeview的使用
- TreeView控件的安装
- .net 的TreeView控件
- .net 的TreeView控件
- TreeView控件的使用
- TreeView 控件的使用
- 高级的TreeView控件
- TreeView控件的使用
- TreeView控件的使用
- oracle :性能优化的一个案例
- 使用SAX解析XML
- 兼容ie firefox select 下拉框 无限级联无刷新下拉框 纯javascript
- Tomcat+Admin
- GridView 72般绝技
- MSDN Sample AccessSiteMapProvider 不能使TreeView控件工作的解决
- 怎样做一个优秀的系统分析师?
- 自己做的一个可以用的webservice,只是开始
- Jpage组件
- C#操作word
- 软件文档编写向导
- 社会
- C#导出数据到Excel中方法总结
- 使用WPF将图片转变为灰度并加上水印并保存为文件