Treeview nodes shows plus sign even though it doesn't have children
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 = rootProductCat开发者_运维技巧egoriesDS.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);
}
精彩评论