asp.net 中从dtree中选择部门

dtree生成部门树的前台

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DeptDtree.aspx.cs" Inherits="Admin_Common_DeptDtree" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<base target="_self" />
<title>请选择部门</title>
<link rel="StyleSheet" type="text/css" href="dtree/dtree.css" />
<link rel="StyleSheet" type="text/css" href="CSS/StyleSheet.css" />

<script type="text/javascript" src="dtree/dtree.js"></script>

<script type="text/javascript">
function SelectDept(menuName){
// alert(menuName);
window.returnValue =menuName;
window.close();
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblDeptTree" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

后台的代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class Admin_Common_DeptDtree : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitTreeData();
}
}
private void InitTreeData()
{
string strMenu;
strMenu = "<script type=\"text/javascript\"> \n";
strMenu += "d = new dTree('d'); \n";
strMenu += "<!-- \n";
strMenu += "d.add(0,-1,'请选择部门'); \n";

#region 从政务平台获取数据
string ipPort = System.Configuration.ConfigurationSettings.AppSettings["ipPort"].ToString();
//先查找,有则删除
string getDeptUrl = "http://" + ipPort + "/mgov1890/im/getAllDepartment.action";
string deptValue = GetWebContent.getContentFromUrl(getDeptUrl, "UTF-8");
#endregion
if (deptValue != "MYERROR")
{
//deptValue = "[1,IT事业部,0,0,0],[3,工商局,0,0,0],[4,教育局,0,0,0],[6,Listong,0,0,0]";
#region 对字符串的处理
deptValue = deptValue.Replace("\r", "");
deptValue = deptValue.Replace("\n", "");
deptValue = deptValue.Replace("],[", "@");
deptValue = deptValue.Replace("[", "");
deptValue = deptValue.Replace("]", "");
#endregion
string[] arrDept = Regex.Split(deptValue, "@", RegexOptions.IgnoreCase);
for (int i = 0; i < arrDept.Length; i++)
{
string[] deptInfo = arrDept[i].Split(',');
int menuid = int.Parse(deptInfo[0]);
string menuname = deptInfo[1];
int pmenuid = int.Parse(deptInfo[2]);
strMenu += "d.add(" + menuid + "," + pmenuid + ",'" + menuname + "',\"javascript:SelectDept('" + menuname + "')\"); \n";
}
}
else
{
strMenu += "d.add(1,0,'暂时没有部门信息'); \n";
}

strMenu += "document.write(d); \n";
strMenu += "//--> \n </script>";
this.lblDeptTree.Text = strMenu;

}
}


调用页面的代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestTreeView.aspx.cs" Inherits="TestTreeView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>测试选择部门</title>
<script type="text/javascript">
function SetDept()
{
var deptName = window.showModalDialog("Admin/DeptDtree.aspx","","dialogWidth:150px;status:auto;dialogHeight:250px");
//alert(deptName);
if(deptName != undefined)
document.getElementById("txtDept").value = deptName;
else
document.getElementById("txtDept").value = "";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtDept" runat="server"></asp:TextBox> <input type="button" value="选择部门" onclick="SetDept()"/>
</div>
</form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值