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 引擎大家都很熟悉,可 ...
随机推荐
- perl 面向对象demo
Vsftp:/root/perl/17# cat Critter.pm package Critter; sub new { my $self = {}; my $invocant = shift; ...
- java httpclient post 文件到server
public void sendFileToServer (String url, File logFiles) { HttpURLConnection connection = nul ...
- 汉企C#面向对象——继承
public class Shengwu { private string _Name; public string Name { get { return _Name; } set { _Name ...
- Continue 的应用(暂时还不大会运用)
static void Main(string[] args) { while (true) { ...
- NOI2003 文本编辑器editor
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 1908 Solved: 738[Submit][Statu ...
- 转自 x_x_的百度空间 搞ACM的你伤不起
来源:http://roba.rushcj.com/?p=548 劳资六年前开始搞ACM啊!!!!!!!!!! 从此踏上了尼玛不归路啊!!!!!!!!!!!! 谁特么跟劳资讲算法是程序设计的核心啊!! ...
- 【转】linux设备驱动之MMC SD卡——核心层简单分析
原文网址:http://blog.chinaunix.net/uid-28685940-id-3889878.html /*************************************** ...
- Toad 中的compare使用方法
1.首先连接要对比后执行的数据库 2.设置对比内容 3.对比后的执行脚本
- JavaScript高级程序设计41.pdf
事件对象 在触发DOM上某个事件时,会产生一个事件对象event,这个对象中包含着所有与事件有关的信息. DOM中的事件对象 兼容DOM的浏览器会将event对象传入到事件处理程序中,无论指定事件处理 ...
- Android TextView : “Do not concatenate text displayed with setText”
参考:http://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-wi ...