asp.net treeView动态增加、编辑、删除 RT..能否点击父节点或叶节点后,进行标题上的操作.希望能有个实例供我参考 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://download.csdn.net/source/1413899 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>"); } } } } }这是我之前做的一个例子 ,你看看 希望能构帮助你 记得给分哦! 选择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(); } } } 求【高手】写一个正则表达式,来替指定格式换字符串【求助】 JS出错。缺少对象 asp.net新闻经典问题…… 投票次数控制 100分求一个正则 关于SQLServer Desktop Engine的部署问题 gridview里隐藏某行 关于生成html静态页面后如何读取在首页上? 怎么利用StateServer在不同的应用程序中传递Session值? 关于dataset 求!!!MSCASI 工具使用方法!! about asp.net ajax
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>");
}
}
}
}
}
这是我之前做的一个例子 ,你看看 希望能构帮助你 记得给分哦!
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();
}
}
}