zoukankan      html  css  js  c++  java
  • 在ASP.NET中ShowModalDialog+ztree的使用

    .aspx:

    <script type="text/javascript">
        function getReturnValue() {
            var strResult = window.showModalDialog('Depart.aspx?random=' + Math.random(), "", "dialogWidth=400px;dialogHeight=500px;status:no");
            if (strResult != undefined) {
                var str = new Array();
                str = strResult.split("|");
                $("#hidId").val(str[0]);
                $("#hidName").val(str[1]);
                $("#txtDepart").val(str[1]);
                //alert(str[1]);
            }
        }
    </script>
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
                <td>
                    请选择:
                </td>
                <td>
                    <asp:TextBox ID="txtDepart" runat="server" CssClass="input required" onclick="getReturnValue();" size="30" ReadOnly="True"></asp:TextBox>
                    <asp:HiddenField ID="hidId" runat="server" />
                    <asp:HiddenField ID="hidName" runat="server" />
                </td>
            </tr>
    </table>
    View Code

    .aspx.cs:只需保存hidId的值

    Depart.aspx:

    <link rel="stylesheet" href="css/demo.css" type="text/css">
        <link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css">
        <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
        <script type="text/javascript" src="js/jquery.ztree.core-3.5.js"></script>
        <SCRIPT type="text/javascript" language="javascript">
            
            var setting = {
                data: {
                    key: {
                        title: "t"
                    },
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    beforeDblClick: zTreeBeforeDblClick,
                    onClick: onClick
                }
            };
    
            var zNodes = <%= sb.ToString() %>;
    
            var log, className = "dark";
            function beforeClick(treeId, treeNode, clickFlag) {
                className = (className === "dark" ? "" : "dark");
                showLog("[ " + getTime() + " beforeClick ]&nbsp;&nbsp;" + treeNode.name);
                return (treeNode.click != false);
            }
            function zTreeBeforeDblClick(treeId, treeNode) {
            if (treeNode != null && treeNode != 'undefined') {
                $("#hidId").val(treeNode.id);
                $("#hidName").val(treeNode.name);
                window.returnValue = $("#hidId").val() + "|" + $("#hidName").val();
                //alert($("#hidId").val() + "|" + $("#hidName").val());
                window.close();
                }
            }
            function onClick(event, treeId, treeNode, clickFlag) {
                //showLog("[ " + getTime() + " onClick ]&nbsp;&nbsp;clickFlag = " + clickFlag + " (" + (clickFlag === 1 ? "普通选中" : (clickFlag === 0 ? "<b>取消选中</b>" : "<b>追加选中</b>")) + ")");
                //window.close();
            }
            function showLog(str) {
                if (!log) log = $("#log");
                log.append("<li class='" + className + "'>" + str + "</li>");
                if (log.children("li").length > 8) {
                    log.get(0).removeChild(log.children("li")[0]);
                }
            }
            function getTime() {
                var now = new Date(),
                h = now.getHours(),
                m = now.getMinutes(),
                s = now.getSeconds();
                return (h + ":" + m + ":" + s);
            }
    
            $(document).ready(function() {
                $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            });
            
        </SCRIPT>
    
    <ul id="treeDemo" class="ztree"></ul>
    <asp:HiddenField ID="hidId" runat="server" />
    <asp:HiddenField ID="hidName" runat="server" />
    View Code

    Depart.aspx.cs:

            public StringBuilder sb = new StringBuilder();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataSet ds;
                    string strSql = "select * from dt_Depart";
                    ds = ZBGA.DBUtility.DbHelperSQL.Query(strSql);
                    sb.Append("[");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        sb.Append("{");
                        string id = ds.Tables[0].Rows[i]["ID"].ToString();
                        sb.Append("id:"" + id + """);
                        sb.Append(",");
                        string pId = ds.Tables[0].Rows[i]["ParentId"].ToString();
                        sb.Append("pId:"" + pId + """);
                        sb.Append(",");
                        string name = ds.Tables[0].Rows[i]["Title"].ToString();
                        sb.Append("name:"" + name + """);
                        sb.Append(",");
                        sb.Append("t:"" + name + """);
                        sb.Append("}");
                        if (i != ds.Tables[0].Rows.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append("]");
                }
            }    
    View Code

     双击某一项后把该项的值传递给父窗口,并关闭自身

  • 相关阅读:
    python写的百度贴吧相册下载
    C#的图片拼接
    删除目录下的所有".svn"文件
    centOS 6.5 yum升级 gcc4.8 然后又退回来4.4
    代理的分类简述特点
    GCC 特性整理
    纯C 实现 strpos substr strspilt str_trim
    编译putty 源码去掉 Are you sure you want to close this session? 提示
    OpenWrt tcpdump 抓包
    安卓 打飞机 app 开发 第一篇
  • 原文地址:https://www.cnblogs.com/liuswi/p/3657113.html
Copyright © 2011-2022 走看看