动态添加的叶子节点怎么去掉前面的+号?
树刚开始是空的:
//初始化
TreeNode NewNode = new TreeNode("根节点", "00");
NewNode.ImageUrl = "../images/OUTOPEN.BMP";
NewNode.PopulateOnDemand = false;
NewNode.Expanded = true;
NewNode.SelectAction = TreeNodeSelectAction.SelectExpand;
TreeNode NewChildNode1 = new TreeNode("节点1", "file");
NewChildNode1.PopulateOnDemand = true;
NewChildNode1.ImageUrl = "../images/OUTCLOSE.BMP";
NewChildNode1.Expanded = false;
NewChildNode1.SelectAction = TreeNodeSelectAction.SelectExpand;
NewNode.ChildNodes.Add(NewChildNode1);
TreeNode NewChildNode2 = new TreeNode("节点2", "item");
NewChildNode2.PopulateOnDemand = true;
NewChildNode2.ImageUrl = "../images/OUTCLOSE.BMP";
NewChildNode2.Expanded = false;
NewChildNode2.SelectAction = TreeNodeSelectAction.SelectExpand;
NewNode.ChildNodes.Add(NewChildNode2);
this.TreeView1.Nodes.Add(NewNode);
这样树就有了1个根2个子节点,现在我需要在单击某个父节点是才动态添加其子节点,比如在点"节点1"时从数据库中读出几条记录添加为"节点1"的子节点,是这样做的:
//点击某个节点时触发
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string sql = "XXXXXXXXX"; //这里根据不同情况拼一条SQL语句
AddChildNodes(TreeView1.SelectedNode, strSql); //调用添加子节点函数
}
//添加子节点
void AddChildNodes(TreeNode node, string strSql)
{
//获取记录
if (node.ChildNodes.Count == 0)
{
foreach (DataRow row in dt.Rows)//把获取的记录一条一条添加为子节点
{
TreeNode NewNode = new TreeNode(row["Name"].ToString(), row["Code"].ToString());
if (row["url"].ToString() != "")
{
NewNode.Expanded = true; //查资料说这样就可以了,但是不行,添加的子节点前面还有加号,用NewNode.Expand(); NewNode.ExpandAll();这些都不行
NewNode.ImageUrl = "images/icon1.gif";
NewNode.NavigateUrl = row["url"].ToString();
NewNode.Target = "right";
NewNode.SelectAction = TreeNodeSelectAction.Select;
}
else
{
NewNode.Expanded = false;
NewNode.SelectAction = TreeNodeSelectAction.SelectExpand;
}
NewNode.PopulateOnDemand = true;
node.ChildNodes.Add(NewNode);
}
}
}
添加上去的子节点前面都有加号,我是不想要加号,因为这已经都是叶子节点了,不该有加号的,请帮忙看下该怎么弄?
------解决方案--------------------NewNode.Expanded = true; //查资料说这样就可以了,但是不行,添加的子节点前面还有加