前台代码:

<link rel="stylesheet" href="../css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="../script/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../script/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="../script/jquery.ztree.excheck-3.5.js"></script>
<script language="javascript" type="text/javascript"> var setting = {
check: {
enable: true,
chkboxType: {"Y":"", "N":""}
},
view: {
dblClickExpand: false
},
data: {
simpleData: {
enable: true
}
},
callback: {
beforeClick: beforeClick,
onCheck: onCheck
}
}; var zNodes =<%= seriesData.ToString() %>; function beforeClick(treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.checkNode(treeNode, !treeNode.checked, null, true);
return false;
} function onCheck(e, treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
nodes = zTree.getCheckedNodes(true),
v = "";
var hidSaveId = "";
for (var i=0, l=nodes.length; i<l; i++) {
v += nodes[i].name + ",";
hidSaveId += nodes[i].id + ",";
}
if (v.length > 0 ) v = v.substring(0, v.length-1);
var cityObj = $("#txtProPlayers");
cityObj.attr("value", v);
var hidObj = $("#hidSaveId");
hidObj.attr("value",hidSaveId);
} function showMenu() {
var cityObj = $("#txtProPlayers");
var cityOffset = $("#txtProPlayers").offset();
$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast"); $("body").bind("mousedown", onBodyDown);
}
function hideMenu() {
$("#menuContent").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);
}
function onBodyDown(event) {
if (!(event.target.id == "menuBtn" || event.target.id == "txtProPlayers" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
hideMenu();
}
} $(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
}); function proSave()
{
var proname = document.getElementById('txtProName').value;
if(proname.length < 1)
{
alert('项目名称不能为空!');
return false;
}
else
{
return true;
}
}
</SCRIPT> <asp:TextBox ID="txtProPlayers" ReadOnly="true" runat="server" Width="300px" onclick="showMenu();" ></asp:TextBox>
<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
<ul id="treeDemo" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
</div>
<asp:HiddenField ID="hidSaveId" runat="server" />

后台代码:

public StringBuilder seriesData = new StringBuilder();
public DataSet ds1;
public DataSet ds2; protected void Page_Load(object sender, EventArgs e)
{
string cmdstr = "";
string cmdstr1 = "";
string name = "";
string no = "";
string departID = "";
string parentID = "";
cmdstr = "select * from tb_Depart";
ds1 = PM.DBUtility.DbHelperSQL.Query(cmdstr);
seriesData.Append("[");
for (int i = ; i < ds1.Tables[].Rows.Count; i++)
{
seriesData.Append("{");
name = ds1.Tables[].Rows[i]["DepartName"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds1.Tables[].Rows[i]["ID"].ToString();
seriesData.Append("id:" + no);
seriesData.Append(",");
parentID = ds1.Tables[].Rows[i]["ParentID"].ToString();
//seriesData.Append("pId:" + parentID);
seriesData.Append("pId:0");
seriesData.Append(",");
seriesData.Append("open:true,nocheck:true}");
if (i != ds1.Tables[].Rows.Count - )
{
seriesData.Append(",");
}
cmdstr1 = "select * from tb_User where DepartID='" + no + "'";
ds2 = PM.DBUtility.DbHelperSQL.Query(cmdstr1);
for (int j = ; j < ds2.Tables[].Rows.Count; j++)
{
seriesData.Append("{");
name = ds2.Tables[].Rows[j]["UserRealName"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds2.Tables[].Rows[j]["ID"].ToString();
seriesData.Append("id:" + no);
seriesData.Append(",");
departID = ds2.Tables[].Rows[j]["DepartID"].ToString();
seriesData.Append("pId:" + departID);
seriesData.Append("}");
if (j != ds2.Tables[].Rows.Count)
{
seriesData.Append(",");
}
}
}
seriesData.Append("]");
} /// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString)
{ using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
return ds;
throw new Exception(ex.Message);
}
return ds;
} } /// <summary>
/// 删除最后结尾的一个逗号
/// </summary>
public static string DelLastComma(string str)
{
return str.Substring(, str.LastIndexOf(","));
}

编辑页后台代码:

        public StringBuilder seriesData = new StringBuilder();
public DataSet ds1;
public DataSet ds2;
public DataSet ds3;
protected void Page_Load(object sender, EventArgs e)
{
string cmdstr = "";
string cmdstr1 = "";
string name = "";
string no = "";
string departID = "";
string parentID = "";
cmdstr = "select * from tb_Depart";
ds1 = PM.DBUtility.DbHelperSQL.Query(cmdstr);
seriesData.Append("[");
for (int i = ; i < ds1.Tables[].Rows.Count; i++)
{
seriesData.Append("{");
name = ds1.Tables[].Rows[i]["DepartName"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds1.Tables[].Rows[i]["ID"].ToString();
seriesData.Append("id:" + no);
seriesData.Append(",");
parentID = ds1.Tables[].Rows[i]["ParentID"].ToString();
//seriesData.Append("pId:" + parentID);
seriesData.Append("pId:0");
seriesData.Append(",");
seriesData.Append("open:true,nocheck:true}");
if (i != ds1.Tables[].Rows.Count - )
{
seriesData.Append(",");
}
cmdstr1 = "select * from tb_User where DepartID='" + no + "'";
ds2 = PM.DBUtility.DbHelperSQL.Query(cmdstr1);
for (int j = ; j < ds2.Tables[].Rows.Count; j++)
{
seriesData.Append("{");
name = ds2.Tables[].Rows[j]["UserRealName"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds2.Tables[].Rows[j]["ID"].ToString();
seriesData.Append("id:" + no);
seriesData.Append(",");
departID = ds2.Tables[].Rows[j]["DepartID"].ToString();
seriesData.Append("pId:" + departID); //默认选中参与人,并赋值给文本框
int id = Convert.ToInt32(Request.QueryString["id"].ToString());
string cmdstr2 = "select ProjectPlayers from tb_Project where ProjectID=" + id;
ds3 = PM.DBUtility.DbHelperSQL.Query(cmdstr2);
string players = ds3.Tables[].Rows[]["ProjectPlayers"].ToString();
string[] str = players.Split(',');
foreach (string key in str)
{
if (key == ds2.Tables[].Rows[j]["ID"].ToString())
{
seriesData.Append(",checked:true");
hidSaveId.Value = ds3.Tables[].Rows[]["ProjectPlayers"].ToString();
txtProPlayers.Text = returnUserName(ds3.Tables[].Rows[]["ProjectPlayers"].ToString());
}
} seriesData.Append("}");
if (j != ds2.Tables[].Rows.Count)
{
seriesData.Append(",");
}
}
}
seriesData.Append("]");
}

     

zTree在Asp.Net中的使用的更多相关文章

  1. 在ASP.NET中ShowModalDialog+ztree的使用

    .aspx: <script type="text/javascript"> function getReturnValue() { var strResult = w ...

  2. ASP.NET中常用的优化性能的方法

    1. 数据库访问性能优化 数据库的连接和关闭 访问数据库资源需要创建连接.打开连接和关闭连接几个操作.这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源.ASP.NET中提供了连接池( ...

  3. asp.net中ashx生成验证码代码放在Linux(centos)主机上访问时无法显示问题

    最近有个项目加入了验证码功能,就从自己博客以前的代码中找到直接使用,直接访问验证码页面报错如下: 源代码:asp.net中使用一般处理程序生成验证码 Application Exception Sys ...

  4. ASP.NET中Session的sessionState 4种mode模式

    1. sessionState的4种mode模式 在ASP.NET中Session的sessionState的4中mode模式:Off.InProc.StateServer及SqlServer. 2. ...

  5. Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值

    Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值,去属性表中设置这时候会提示你去属性表中更改返回类型. 其实存储过程返回的也是一张表,只不过有时候存储过程有点复杂或者写法不规范的话不能 ...

  6. ASP.NET中后台数据和前台控件的绑定

    关于ASP.NET中后台数据库和前台的数据控件的绑定问题 最近一直在学习个知识点,自己创建了SQL Server数据库表,想在ASP.NET中连接数据库,并把数据库中的数据显示在前台,注意,这里的数据 ...

  7. asp.net中缓存的使用介绍一

    asp.net中缓存的使用介绍一 介绍: 在我解释cache管理机制时,首先让我阐明下一个观念:IE下面的数据管理.每个人都会用不同的方法去解决如何在IE在管理数据.有的会提到用状态管理,有的提到的c ...

  8. ASP.NET中Ajax的用法

    在ASP.NET中应用Ajax的格式如下: 前台代码(用JQuery库) $.ajax({ type: "POST", async: true, url: "../Aja ...

  9. Asp.Net中使用OpenRowSet操作Excel表,导入Sql Server(实例)

    有两种接口可供选择:Microsoft.Jet.OLEDB.4.0(以下简称 Jet 引擎)和Microsoft.ACE.OLEDB.12.0(以下简称 ACE 引擎). Jet 引擎大家都很熟悉,可 ...

随机推荐

  1. HDU 3308 LCIS 线段树区间更新

    最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛  ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...

  2. SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在Java配置文件中引入xml配置文件@Import、@ImportResource

    1. package soundsystem; import org.springframework.beans.factory.annotation.Autowired; public class ...

  3. Windows下Redis中RedisQFork位置调整

    redis-server.exe redis.windows.conf 使用上面命令启动redis服务的时候报了以下错误信息: The Windows version of Redis allocat ...

  4. 检查并创建目录mkdir

    os.listdir() os.path.isdir() os.path.join() os.mkdir() # -*- coding:utf-8 -*- import os,sys def mkdi ...

  5. Linux修改文件时候出现崩溃,产生了一个.swap交换文件,如何修复?

    有时候在用vim打开文件时提示类似以下的信息: E325: 注意 发现交换文件 ".exportcert.cpp.swp" 所有者: liuchuanliang    日期: Th ...

  6. WordPress 'is_serialized()'远程任意代码执行漏洞(CVE-2013-4338)

    漏洞版本: WordPress 3.6 漏洞描述: Bugtraq ID:62345 CVE ID:CVE-2013-4338 WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PH ...

  7. 如用使用高版本framework,比如支持iOS5及以上的工程中使用Social.framework

    在Targets -> Build Phases里的 Link Binary With Libraries项中,将高版本的framework,如Social.framework 设置成Optio ...

  8. 转载--C语言运算符优先级和口诀

    转载:http://www.cnblogs.com/zhanglong0426/archive/2010/10/06/1844700.html 一共有十五个优先级: 1   ()  []  .  -& ...

  9. 荷兰国旗问题 划分成3部分 leecode

    public class Solution { public void sortColors(int[] A) { int len=A.length; int beg=0; int end=len-1 ...

  10. Oracle创建表空间、创建用户、授权用户、导入dmp备份语句

    create tablespace TOPSCF_CHS_TS datafile 'D:\TableSpace\TOPSCF_CHS_TS.dbf' size 512M  extent managem ...