日期:2011-10-04  浏览次数:20483 次

本实例完成TreeView树型菜单添加,修改,删除,绑定DropDownList功能,移动功能读者可以自行书写
.aspx代码

<form id="Form1" method="post" runat="server">
   <FONT face="宋体">
    <TABLE id="Table1" cellSpacing="1" cellPadding="1"

width="700" border="1">
     <TR>
      <TD style="WIDTH: 168px"></TD>
      <TD>TreeView操作实例</TD>
     </TR>
     <TR>
      <TD style="WIDTH: 168px" vAlign="top">
       <iewc:TreeView id="TreeView1"

runat="server"></iewc:TreeView></TD>
      <TD vAlign="top">
       <TABLE id="Table2" cellSpacing="1"

cellPadding="1" width="100%" border="0">
        <TR>
         <TD>节点名
          <asp:TextBox

id="TextBox1" runat="server"></asp:TextBox></TD>
        </TR>
        <TR>
         <TD>
          <asp:Button

id="addButton" runat="server" Text="添 加"></asp:Button>
          <asp:Button

id="editButton" runat="server" Text="修 改"></asp:Button>
          <asp:Button

id="delButton" runat="server" Text="删 除"></asp:Button></TD>
        </TR>
        <TR>
         <TD>移动节点</TD>
        </TR>
        <TR>
         <TD>要移动到的节点
          

<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList></TD>
        </TR>
        <TR>
         <TD>
          <asp:Button

id="moveButton" runat="server" Text="移 动"></asp:Button></TD>
        </TR>
       </TABLE>
      </TD>
     </TR>
     <TR>
      <TD style="WIDTH: 168px"></TD>
      <TD></TD>
     </TR>
    </TABLE>
   </FONT>
  </form>

.aspx.cs后台代码

protected Microsoft.Web.UI.WebControls.TreeView TreeView1; 
  public string returnvalue="";//递归存储值


  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!Page.IsPostBack){
    Button del=new Button();
    del=(Button)Page.FindControl("delButton");
    del.Attributes.Add("onclick","return confirm('