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 引擎大家都很熟悉,可 ...
随机推荐
- VS2008编译器编译出来的文件比mingw编译的要几乎小一半
为什么要在VS2008中使用QT静态编译呢?很简单,因为VS2008编译器编译出来的文件比mingw编译的要几乎小一半. 好了现在我们来做些准备工作,VS2008自然要安装的,然后打上SP1的补丁.然 ...
- PEP Index > PEP 339 -- Design of the CPython Compiler 译文
http://www.python.org/dev/peps/pep-0339/ PEP: 339 标题: CPython的编译器设计 版本: 425fc5598ee8 最后修改: 2011-01-1 ...
- 转:三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)
转:http://blog.csdn.net/liujun13579/article/details/7773945 卡片布局能够让多个组件共享同一个显示空间,共享空间的组件之间的关系就像一叠牌,组件 ...
- C# 如何为应用程序加入多个图标?
对于WINDOWS XP操作系统,浏览文件时有列表,图标和平铺三种,显示出文件图标的大小分别为16x16,32x32,48x48这三种尺寸.有些程序包含这三个尺寸的图标,随着浏览文件时的设置来选择尺寸 ...
- MySQL源码 数据结构array
MySQL源码中自己定义了许多数据结构,放在mysys的目录下,源码中通常都使用这些数据结构来组织存放数据,也更容易实现跨平台. 下面先来看下MySQL定义的动态数组: [源代码include/a ...
- bzoj1023
研究了一下仙人掌首先,仙人掌虽然不是树,但却有很强的树的既视感如果把每个环都看做一个点,那么他就是一棵树当然这不能直接缩环,因为环和环可以有一个交点如果是树,求直径都会做,令f[i]表示i到子树的最长 ...
- 遍历Dataset并输出数据实例
转自:http://www.cnblogs.com/csdm/archive/2010/02/02/1661808.html <%@ Page Language="C#" A ...
- List迭代循环时出现分问题
一个List,通过迭代之后给List中的实体重新赋值,代码如下 public List getListByPage(Page currPage) { Map recordTypeMap = BusnD ...
- 完美转换MySQL的字符集 Mysql 数据的导入导出,Mysql 4.1导入到4.0
MySQL从4.1版本开始才提出字符集的概念,所以对于MySQL4.0及其以下的版本,他们的字符集都是Latin1的,所以有时候需要对mysql的字符集进行一下转换,MySQL版本的升级.降级,特别是 ...
- hdoj 2404 Permutation Recovery【逆序对】
Permutation Recovery Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...