RT..能否点击父节点或叶节点后,进行标题上的操作.希望能有个实例供我参考

解决方案 »

  1.   

    http://download.csdn.net/source/1413899
      

  2.   

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using MyContent.Model;
    using MyContent.BLL;
    using System.Collections.Generic;public partial class admin_dianpu_DianpuTypeManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString.Count != 0)
                {
                    int id = Convert.ToInt32(Request.QueryString["id"].ToString());
                    Leixing tp = LeixingManager.GetLeixingById(id);
                    this.txtName.Text = tp.Tname;
                }
                BindTypeBig();
                ShowTreeView();
            }
        }
        //填充dropdownlist行业类型
        public void BindTypeBig()
        {
            IList<Leixing> comps = LeixingManager.GetAllLeixingByTid(0);
            this.ddlAllType.Items.Add("请选择");
            foreach (Leixing compt in comps)
            {
                ListItem item = new ListItem();
                item.Value = compt.Tid.ToString();
                item.Text = compt.Tname;
                this.ddlAllType.Items.Add(item);
            }
        }
        //填充TreeVView
        public void ShowTreeView()
        {
            IList<Leixing> lists = LeixingManager.GetAllLeixingByTid(0);
            foreach (Leixing item in lists)
            {
                //创建父节点
                TreeNode father = this.CreateTreeNode(item.Tname, item.Tid.ToString(), "DianpuTypeManager.aspx?id=" + item.Tid, "images/OpenTree.gif");
                CreateChildNode(item.Tid, father);
                this.tvProductType.Nodes.Add(father);
            }
        }
        //创建子节点
        public void CreateChildNode(int typeId, TreeNode fatherNode)
        {
            IList<Leixing> lists = LeixingManager.GetAllLeixingByTid(typeId);
            foreach (Leixing item in lists)
            {
                TreeNode child = this.CreateTreeNode(item.Tname, item.Tid.ToString(), "DianpuTypeManager.aspx?id=" + item.Tid, "images/OpenTree.gif");
                CreateChildNode(item.Tid, child);
                AddTree(fatherNode, child);
            }
        }
        //把子节点加入父节点
        private void AddTree(TreeNode father, TreeNode child)
        {
            father.ChildNodes.Add(child);
        }
        //创建树的节点
        public TreeNode CreateTreeNode(string name, string id, string url, string img)
        {
            TreeNode node = new TreeNode();
            node.Text = name;
            node.Value = id;
            node.NavigateUrl = url;
            node.ImageUrl = img;
            return node;
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (this.ddlAllType.Text == "请选择")
            {
                if (this.txtName.Text.Trim() == "")
                {
                    ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('修改时,类型名不能为空!'),window.location='DianpuTypeManager.aspx'", true);
                    //Response.Write("<script> alert('修改时,类型名不能为空!');location='DianpuTypeManager.aspx';</script>");
                }
                else if (this.txtName.Text.Trim() != "")
                {
                    int id = Convert.ToInt32(Request.QueryString["id"].ToString());//获取所选的节点ID
                    if (LeixingManager.UpdateLeixingByNameAndId(this.txtName.Text.Trim().ToString(), id) > 0)
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('修改成功!'),window.location='DianpuTypeManager.aspx'", true);
                        //Response.Write("<script> alert('修改成功!');location='DianpuTypeManager.aspx';</script>");
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('修改失败!'),window.location='DianpuTypeManager.aspx'", true);
                        //Response.Write("<script> alert('修改失败!');location='DianpuTypeManager.aspx';</script>");
                    }
                }
            }
            else
            {
                if (this.txtName.Text.Trim() == "")
                {
                    ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('修改时,类型名不能为空!'),window.location='DianpuTypeManager.aspx'", true);
                    //Response.Write("<script> alert('修改时,类型名不能为空!');location='DianpuTypeManager.aspx';</script>");
                }
                else if (this.txtName.Text.Trim() != "")
                {
                    int id = Convert.ToInt32(Request.QueryString["id"].ToString());//获取所选的节点ID
                    int parentId = Convert.ToInt32(this.ddlAllType.SelectedValue.ToString());
                    if (LeixingManager.UpdateLeixingByParentIdAndId(parentId, id) > 0)
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('修改成功'),window.location='DianpuTypeManager.aspx'", true);
                        //Response.Write("<script> alert('修改成功!');location='DianpuTypeManager.aspx';</script>");
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('修改失败!'),window.location='DianpuTypeManager.aspx'", true);
                        //Response.Write("<script> alert('修改失败!');location='DianpuTypeManager.aspx';</script>");
                    }
                }
            }        
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"].ToString() == null)
            {
                ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('删除时:请选择删除项!'),window.location='DianpuTypeManager.aspx'", true);
                //Response.Write("<script> alert('删除时:请选择删除项!');location='DianpuTypeManager.aspx';</script>");
            }
            else
            {
                int id = Convert.ToInt32(Request.QueryString["id"].ToString());//获取所选的节点ID
                if (LeixingManager.GetAllLeixingByTid(id).Count != 0)
                {
                    ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('请查看相关链接,再行删除'),window.location='DianpuTypeManager.aspx'", true);
                    //Response.Write("<script>alert('请查看相关链接,再行删除');location='DianpuTypeManager.aspx';</script>");
                }
                else
                {
                    if (LeixingManager.DeleteLeixingByID(id) > 0)
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('删除成功!'),window.location='DianpuTypeManager.aspx'", true);
                        //Response.Write("<script> alert('删除成功!');location='DianpuTypeManager.aspx';</script>");
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "", "alert('删除失败!'),window.location='DianpuTypeManager.aspx'", true);
                        //Response.Write("<script> alert('删除失败!');location='DianpuTypeManager.aspx';</script>");
                    }
                }
            }
            
        }
        
    }
    这是我之前做的一个例子 ,你看看 希望能构帮助你   记得给分哦!
      

  3.   

    选择treeview节点seletedindexchange中显示数据修改保存
      protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            if (this.TreeView1.SelectedNode != null)
            {
                string XTBH = this.TreeView1.SelectedNode.Value.Trim();
                if (this.TreeView1.SelectedNode.Value.Trim() != "0")
                {
                    this.Hd_XTBH.Value = XTBH;
                    DataSet ds = this.GetJgxx(XTBH, false);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        txtbmmc.Text = ds.Tables[0].Rows[0]["jigmc"].ToString();
                        txtbmbh.Text = ds.Tables[0].Rows[0]["jigbh"].ToString();
                    }
                }
                else
                {
                    txtbmbh.Text = "";
                    txtbmmc.Text =TreeView1.SelectedNode.Text.Trim();
                }
            }
        }