zTree在Asp.Net中的使用
前台代码:
<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中的使用的更多相关文章
- 在ASP.NET中ShowModalDialog+ztree的使用
.aspx: <script type="text/javascript"> function getReturnValue() { var strResult = w ...
- ASP.NET中常用的优化性能的方法
1. 数据库访问性能优化 数据库的连接和关闭 访问数据库资源需要创建连接.打开连接和关闭连接几个操作.这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源.ASP.NET中提供了连接池( ...
- asp.net中ashx生成验证码代码放在Linux(centos)主机上访问时无法显示问题
最近有个项目加入了验证码功能,就从自己博客以前的代码中找到直接使用,直接访问验证码页面报错如下: 源代码:asp.net中使用一般处理程序生成验证码 Application Exception Sys ...
- ASP.NET中Session的sessionState 4种mode模式
1. sessionState的4种mode模式 在ASP.NET中Session的sessionState的4中mode模式:Off.InProc.StateServer及SqlServer. 2. ...
- Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值
Asp.net中存储过程拖拽至dbml文件中,提示无法获得返回值,去属性表中设置这时候会提示你去属性表中更改返回类型. 其实存储过程返回的也是一张表,只不过有时候存储过程有点复杂或者写法不规范的话不能 ...
- ASP.NET中后台数据和前台控件的绑定
关于ASP.NET中后台数据库和前台的数据控件的绑定问题 最近一直在学习个知识点,自己创建了SQL Server数据库表,想在ASP.NET中连接数据库,并把数据库中的数据显示在前台,注意,这里的数据 ...
- asp.net中缓存的使用介绍一
asp.net中缓存的使用介绍一 介绍: 在我解释cache管理机制时,首先让我阐明下一个观念:IE下面的数据管理.每个人都会用不同的方法去解决如何在IE在管理数据.有的会提到用状态管理,有的提到的c ...
- ASP.NET中Ajax的用法
在ASP.NET中应用Ajax的格式如下: 前台代码(用JQuery库) $.ajax({ type: "POST", async: true, url: "../Aja ...
- Asp.Net中使用OpenRowSet操作Excel表,导入Sql Server(实例)
有两种接口可供选择:Microsoft.Jet.OLEDB.4.0(以下简称 Jet 引擎)和Microsoft.ACE.OLEDB.12.0(以下简称 ACE 引擎). Jet 引擎大家都很熟悉,可 ...
随机推荐
- 基于Spring Boot构建的Spring MVC快速入门
原文地址:http://tianmaying.com/tutorial/spring-mvc-quickstart 环境准备 一个称手的文本编辑器(例如Vim.Emacs.Sublime Text)或 ...
- RocketMQ在windows上安装和开发使用
1.概述 RocketMQ是alibaba公司开源的一个纯java的开源消息中间件. 2.开发测试环境搭建 到github上面rocketMQ,我选择的是alibaba-rocketmq-3.2.6. ...
- leetcode面试准备:Minimum Size Subarray Sum
leetcode面试准备:Minimum Size Subarray Sum 1 题目 Given an array of n positive integers and a positive int ...
- Codevs_1690_开关灯_(线段树)
描述 http://codevs.cn/problem/1690/ 一排共 n 个灯,起初都是关着的,现在有 m 次操作. 0 开头的操作代表将 l ~ r 的开关按一遍,1 开头的操作代表询问 l ...
- Makefile第二讲:打印出内容和使用变量
摘要 `@echo "开始生成最终执行文件,请稍候..."`这一句便是将一条信息输出到终端,为何前边有个`@`符号呢?有了这个符号该命令本身就不会输出到终端(不理解,自己去掉或者加 ...
- [转]NHibernate之旅(5):探索Insert, Update, Delete操作
本节内容 操作数据概述 1.新建对象 2.删除对象 3.更新对象 4.保存更新对象 结语 操作数据概述 我们常常所说的一个工作单元,通常是执行1个或多个操作,对这些操作要么提交要么放弃/回滚.想想使用 ...
- arcGis引入Dll报无法嵌入互操作类型错误解决方法
arcGis引入Dll报“无法嵌入互操作类型"ESRI.ARCGIS.Geometry.PointClass".请改用通用接口." 解决方法:设置引用DLL的“嵌入互 ...
- JVM performance profiling (有待整理)
Agenda memory model 3 parts: heap, permgen (method area) , thread stack(pointer, local var) heap: yo ...
- java 学习笔记4
(1) 线程的强制运行 先看线程强制运行的实例 ,再解释程序中是如何让程序强制运行的 public class ThreadTest1 implementsRunnable { public ...
- HDU4283:You Are the One(区间DP)
Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...