我的Treeview默认显示所有节点上的加号。 即使那些没有孩子的节点也是错误的。
但是,一旦我尝试扩展该节点,加号就会消失。
我动态填充Treeview。
以下是一些代码:
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);
}