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 引擎大家都很熟悉,可 ...
随机推荐
- 【BZOJ 3122】 [Sdoi2013]随机数生成器 (BSGS)
3122: [Sdoi2013]随机数生成器 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1442 Solved: 552 Description ...
- WordPress Bradesco Gateway插件‘falha.php’跨站脚本漏洞
漏洞名称: WordPress Bradesco Gateway插件‘falha.php’跨站脚本漏洞 CNNVD编号: CNNVD-201309-451 发布时间: 2013-09-26 更新时间: ...
- VM Depot 喜迎中国本土开源镜像!
发布于 2014-04-07 作者 陈 忠岳 VM Depot 登陆中国之际,我非常高兴地告诉大家,一批各位耳熟能详的中国本地开源镜像已同时上线!得益于开源社区的大力支持,Ubuntu 麒麟13 ...
- 利用spm提供的MoAEpilot听觉数据学习预处理以及单被试glm分析与统计推断
1.数据介绍 下载:http://www.fil.ion.ucl.ac.uk/spm/data/auditory/ SUBJECT:1 VOLUME: 64*64*64 TR:7s total acq ...
- Away3d 基础 1 ---对一个简单类的解释
转自:http://www.cnblogs.com/nooon/archive/2009/05/16/1458334.html 原英文地址: http://www.flashmagazine.com/ ...
- 基础算法(搜索):NOIP 2015 斗地主
Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3& ...
- Oracle 视图添加主键
在Entity Framework中,从数据库生成模型,视图常报无主键. 解决办法:为试图添加主键/复合主键 create or replace view view_activebudgetamoun ...
- poj 2932 Coneology(扫描线+set)
Coneology Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3574 Accepted: 680 Descript ...
- jQuery 参考手册 - 文档操作
上传图片时页面崩溃..全部付之东流 addClass() after() append() appendTo() attr() before() clone() detach() empty() ha ...
- [ZETCODE]wxWidgets教程九:组件专题2
本教程原文链接:http://zetcode.com/gui/wxwidgets/widgetsII/ 翻译:瓶哥 日期:2013年12月15日星期日 邮箱:414236069@qq.com 主页:h ...