100分求一无刷新增加、修改、删除TreeView的例子

clj2201 2010-08-02 04:48:09
小弟做了三年WinForm,忽然遇到个WebForm的项目,做个TreeView实在是搞不定了,网上看了一大堆,但是实在是调试不通过,那位老大有实际的例子希望发给给我

要求:
类似于增加全国各地省份地区的例子,如下



北京
昌平
海淀
山东
济南
市中区
天桥区
潍坊


无刷新,带有增、删、该操作,无论实现方法(Ajax\Jquery)都可以?

哪位老大做过实际的项目,可以从里面把这可以块的实际代码摘出来发给我,多谢多谢~~

Email:clj2201@126.com
邮件注明 CSDN 的ID,解决后马上给分~~

再次万分感谢~~
...全文
359 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
clj2201 2010-08-04
  • 打赏
  • 举报
回复
然没搞定,但还是给分吧~~
yjp2006 2010-08-03
  • 打赏
  • 举报
回复
很好,,来学习下。。呵呵
clj2201 2010-08-03
  • 打赏
  • 举报
回复
如果用updatepanel,如何做到当对节点增、删、该得时候仅仅是局部节点刷新,而不是整个都要刷一次?
zzxap 2010-08-03
  • 打赏
  • 举报
回复
http://download.csdn.net/source/2261699
shichao102471077 2010-08-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
updatepanel
http://www.open-open.com/ajax/Tree.htm
[/Quote]

最简单的就是用内置的updatepanel

这个网站和受用 搜藏慢慢看了。、顶
浅陌 2010-08-03
  • 打赏
  • 举报
回复
学习了
zzxap 2010-08-03
  • 打赏
  • 举报
回复
有一个套叫updatepanel
clj2201 2010-08-03
  • 打赏
  • 举报
回复
有没有更好的方法??
因为用UpdatePanel每次删除、修改、增加后都要重新从数据库取数据,把整个树在Build一下,有没有更好的办法???
阿彪兄 2010-08-02
  • 打赏
  • 举报
回复
是的,最简单的方法除了用UpdatePanel外,还可以用iframe
clj2201 2010-08-02
  • 打赏
  • 举报
回复
IHandler 的方法我试过,可以,但是有个问题是每次修改、删除后倒要吧整个树重新 从数据库 取一遍呀~~
lihongxian 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
updatepanel
http://www.open-open.com/ajax/Tree.htm
[/Quote]
可以模仿改一下
leejelen 2010-08-02
  • 打赏
  • 举报
回复
不是用UpDatePanel么!
yzf86211861 2010-08-02
  • 打赏
  • 举报
回复
学习 帮顶
zl402263140 2010-08-02
  • 打赏
  • 举报
回复
直接用AJax控件不就搞定了
IHandler 2010-08-02
  • 打赏
  • 举报
回复
参考一下实现

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Category.aspx.cs" Inherits="Files_Category" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="../Style/net.css" type="text/css" rel="stylesheet" />

<script src="../JS/functions.js" type="text/javascript"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
function GoClick() {
if (event.srcElement.tagName.toLowerCase() == "input") {
//alert(event.srcElement.nextSibling);
event.srcElement.nextSibling.click();

}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:TreeView ID="tvCategory" runat="server" OnTreeNodeCheckChanged="tvCategory_TreeNodeCheckChanged"
ShowCheckBoxes="All" OnClick="javascript:GoClick();"
ImageSet="XPFileExplorer">
</asp:TreeView>
</div>
<div>
<asp:ImageButton ID="imgbtnEdit" runat="server" ImageUrl="~/Images/button/btn_Edit.gif"
CausesValidation="False" OnClick="imgbtnEdit_Click" />
 
<asp:ImageButton ID="imgbtnDel" runat="server" ImageUrl="~/Images/button/btn_Del.gif"
CausesValidation="False" onclick="imgbtnDel_Click" />
</div>
<div>
分类名称:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="必填项"
ControlToValidate="txtName" Display="Dynamic"></asp:RequiredFieldValidator>
分类编码:<asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="必填项"
ControlToValidate="txtCode" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:CheckBox ID="cbRoot" runat="server" Text="根节点" />
</div>
<div>
<asp:ImageButton ID="imgbtnSave" runat="server" ImageUrl="~/Images/button/btn_Save.gif"
OnClick="imgbtnSave_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
正在处理......
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TancCmsModels;

public partial class Files_Category : System.Web.UI.Page
{
DAOGTFileCategory dao = new DAOGTFileCategory();
GTFileCategory ins = null;
IList<GTFileCategory> list = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
imgbtnDel.Attributes.Add("onclick", "return confirm('确定要删除吗?');");
ViewState["Action"] = "add";
ViewState["Node"] = null;
this.BindTree();
}
}

private void BindTree()
{
tvCategory.Nodes.Clear();
list = dao.GetAllCategories();
IList<GTFileCategory> listTop = list.Where(m => m.ParentID == 0).OrderBy(m =>m.CName).ToList();
foreach (GTFileCategory c in listTop)
{
TreeNode node = new TreeNode();
node.Text = c.CName;//+ "(" + c.CCode + ")";
node.ToolTip = c.CCode;
node.Value = c.CCode + ";" + c.ID;
BindChild(node);
tvCategory.Nodes.Add(node);
}
tvCategory.ExpandAll();
}

private void BindChild(TreeNode parentNode)
{
IList<GTFileCategory> listChild = list.Where(m => m.ParentID == Int32.Parse(parentNode.Value.Split(';')[1])).OrderBy(m => m.CName).ToList();
foreach (GTFileCategory c in listChild)
{
TreeNode node = new TreeNode();
node.Text = c.CName; //+ "(" + c.CCode + ")";
node.ToolTip = c.CCode;
node.Value = c.CCode + ";" + c.ID;
BindChild(node);
parentNode.ChildNodes.Add(node);
}
}

protected void imgbtnSave_Click(object sender, ImageClickEventArgs e)
{
if (IsValid)
{
if (ViewState["Action"] != null)
{
String strName = txtName.Text.Trim();
String strCode = txtCode.Text.Trim();
if (ViewState["Action"].ToString() == "add")
{
#region
ins = new GTFileCategory();
ins.CName = strName;
ins.CCode = strCode;
if (cbRoot.Checked)
{
ins.ParentID = 0;
}
else
{
if (tvCategory.CheckedNodes.Count > 0)
{
ins.ParentID = Int32.Parse(tvCategory.CheckedNodes[0].Value.Split(';')[1]);
}
else
{
ScriptManager.RegisterStartupScript(
this, this.GetType(), "JSParentSel", "alert('请选择父节点!')", true);
return;
}
}
dao.Save(ins);
#endregion
}
if (ViewState["Action"].ToString() == "edit")
{
ins = dao.GetCategoryById(Int32.Parse(tvCategory.CheckedNodes[0].Value.Split(';')[1]))[0];
ins.CName = strName;
ins.CCode = strCode;
dao.Update(ins);
}

this.txtName.Text = this.txtCode.Text = "";

this.BindTree();

cbRoot.Enabled = true;

}

}

ViewState["Action"] = "add";
}
protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
{
if (tvCategory.CheckedNodes.Count > 0)
{
ViewState["Action"] = "edit";
TreeNode node = tvCategory.CheckedNodes[0];
txtName.Text = node.Text;
txtCode.Text = node.Value.Split(';')[0];
cbRoot.Enabled = false;
}
else
{
ScriptManager.RegisterStartupScript(
this, this.GetType(), "JSEdit", "alert('请选择要修改的节点!')", true);
}
}


protected void tvCategory_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
for (int i = 0; i < tvCategory.CheckedNodes.Count;i++ )
{
if (tvCategory.CheckedNodes[i] != e.Node)
{
tvCategory.CheckedNodes[i].Checked = false;
}
}
}
protected void imgbtnDel_Click(object sender, ImageClickEventArgs e)
{
if (tvCategory.CheckedNodes.Count > 0)
{
TreeNode node = tvCategory.CheckedNodes[0];
Int32 ID = Int32.Parse(node.Value.Split(';')[1]);
dao.Delete(dao.GetCategoryById(ID)[0]);
this.BindTree();
}
else
{
ScriptManager.RegisterStartupScript(
this, this.GetType(), "JSDel", "alert('请选择要删除的节点!')", true);
}
}
}

vip__888 2010-08-02
  • 打赏
  • 举报
回复

套一下就行了
JiuchunYoung 2010-08-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
updatepanel
http://www.open-open.com/ajax/Tree.htm
[/Quote]

顶楼上的 改改内容 就OK了 加油哦
wuyq11 2010-08-02
  • 打赏
  • 举报
回复

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧