aspx代码
<div style="float:left">
<asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" Width="221px">
<Nodes>
<asp:TreeNode Text="根1" Value="1">
<asp:TreeNode Text="1.1" Value="1.1"></asp:TreeNode>
<asp:TreeNode Text="1.2" Value="1.2"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="根2" Value="2">
<asp:TreeNode Text="2.1" Value="2.1"></asp:TreeNode>
<asp:TreeNode Text="2.2" Value="2.2"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode Text="XXX成本管理" Value="3">
<asp:TreeNode Text="小易" Value="3.1"></asp:TreeNode>
<asp:TreeNode Text="www" Value="3.2"></asp:TreeNode>
<asp:TreeNode Text="rrrr" Value="rrrr"></asp:TreeNode>
<asp:TreeNode Text="yyyy" Value="yyyy"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
<asp:ListBox ID="ListBox1" runat="server" Height="225px" Width="265px" SelectionMode="Single"></asp:ListBox>
<asp:Button ID="btn02" runat="server" OnClick="btn02_Click" Text="删除"/>
aspx.cs代码
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
InsertListBox();
}
private void InsertListBox()
{
if (this.TreeView1.SelectedNode.Parent.Value=="3")
{
if (this.ListBox1.Items.FindByValue(this.TreeView1.SelectedNode.Value) == null)
{
ListItem list = new ListItem(this.TreeView1.SelectedNode.Text, this.TreeView1.SelectedNode.Value);
this.ListBox1.Items.Add(list);
}
}
}
protected void btn02_Click(object sender, EventArgs e)
{
this.ListBox1.Items.Remove(this.ListBox1.SelectedItem);
}
希望是你想要的效果
谢谢啦
期待学习。。。