树视图节点显示加号,即使它没有子节点
默认情况下,我的树视图在所有节点上显示加号。 即使那些没有子节点的节点也是错误的。
但是,一旦我尝试展开该节点,加号就会消失。
我动态填充树视图。
这是一些代码:
protected void CategoriesTreeView_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
populateSubLevel(Int32.Parse(e.Node.Value), e.Node);
}
private void populateRootLevel()
{
DataSet rootProductCategoriesDS = myDALObject.getRootProductCategories_DAL(false);
DataTable rootProductCategoriesDT = rootProductCategoriesDS.Tables[0];
populateNodes(rootProductCategoriesDT, CategoriesTreeView.Nodes, true);
}
private void populateNodes(DataTable dt, TreeNodeCollection nodes, bool rootLevel)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
//tn.Text = dr["CategoryName"].ToString();
if (rootLevel)
{
tn.Text = String.Format("<span class=\"root-menu-item\">{0}</strong>", dr["CategoryName"].ToString());
}
else
{
tn.Text = dr["CategoryName"].ToString();
}
tn.Value = dr["CategoryId"].ToString();
tn.NavigateUrl = "Category.aspx?CategoryID=" + dr["CategoryId"].ToString();
// Collapse som standard.
tn.Expanded = false;
for (int i = 0; i < categories.Length; i++)
{
// Expandera om den finns med.
if (categories[i] == dr["CategoryID"].ToString())
{
tn.Expanded = true;
}
}
nodes.Add(tn);
//If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0);
}
}
private void populateSubLevel(int parentid, TreeNode parentNode)
{
DataSet myDataset;
myDataset = myDALObject.getChildProductCategories_DAL(parentid, false);
populateNodes(myDataset.Tables[0], parentNode.ChildNodes, false);
}
My Treeview shows the plus sign on all nodes, by default.
Even those nodes without children, which is wrong.
However, once I've tried to expand that node, the plus sign disappears.
I populate the Treeview dynamically.
Here's some code:
protected void CategoriesTreeView_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
populateSubLevel(Int32.Parse(e.Node.Value), e.Node);
}
private void populateRootLevel()
{
DataSet rootProductCategoriesDS = myDALObject.getRootProductCategories_DAL(false);
DataTable rootProductCategoriesDT = rootProductCategoriesDS.Tables[0];
populateNodes(rootProductCategoriesDT, CategoriesTreeView.Nodes, true);
}
private void populateNodes(DataTable dt, TreeNodeCollection nodes, bool rootLevel)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
//tn.Text = dr["CategoryName"].ToString();
if (rootLevel)
{
tn.Text = String.Format("<span class=\"root-menu-item\">{0}</strong>", dr["CategoryName"].ToString());
}
else
{
tn.Text = dr["CategoryName"].ToString();
}
tn.Value = dr["CategoryId"].ToString();
tn.NavigateUrl = "Category.aspx?CategoryID=" + dr["CategoryId"].ToString();
// Collapse som standard.
tn.Expanded = false;
for (int i = 0; i < categories.Length; i++)
{
// Expandera om den finns med.
if (categories[i] == dr["CategoryID"].ToString())
{
tn.Expanded = true;
}
}
nodes.Add(tn);
//If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0);
}
}
private void populateSubLevel(int parentid, TreeNode parentNode)
{
DataSet myDataset;
myDataset = myDALObject.getChildProductCategories_DAL(parentid, false);
populateNodes(myDataset.Tables[0], parentNode.ChildNodes, false);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论