梅花雪js树2.0版本带checkbox获取选中值例子,[asp.net基础]

带checkbox的梅花雪js树,数据绑定,取得选中值。

梅花雪js树2.0版本带checkbox获取选中值例子,[asp.net基础]

mztree_c.aspx代码:


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

<html>
<head id="Head1" runat="server">
    <title>bubufx,tech.bubufx.com,布布分享</title>
    <script src="treescripts/jsframework.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function PushCheckItems(obj) {
            var IDs = "#";
            var nodes = obj.nodes;
            for (var i in nodes) {

                if (nodes[i].checked) {
                    IDs = IDs + nodes[i].id + "#";
                }
            }

            var hf = document.getElementById(’<%=hfChecked.ClientID %>’);
            hf.value = IDs;
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width="800" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="50">
                    &nbsp;
                </td>
                <td>
                    <div style="width: 300px; height: 500px; overflow: auto;">
                        <script language="JavaScript" type="text/javascript">
                        var data = {};
                        <%=treeone %>

                        var xmlstr = "<%=tree %>";

                        //*
                        Using("System.Web.UI.WebControls.MzTreeView");
                        var a = new MzTreeView();
                        a.dataSource = data
                        a.loadXmlDataString(xmlstr, ’0’);

                        a.autoSort = false;
                        a.useCheckbox = true
                        a.canOperate = true;
                        document.write(a.render());
                        a.expandLevel(6);
                        //*/

                        </script>
                    </div>
                </td>
                <td width="400" valign="top">
                    <asp:Button ID="Button1" runat="server" Text="获得选中值" onclick="Button1_Click" />
                    <asp:HiddenField ID="hfChecked" runat="server" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
mztree_c.aspx.cs:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

public partial class mztree_c : System.Web.UI.Page
{
    public string tree = "";
    public string treeone = "";

    protected void Page_Load(object sender, EventArgs e)
    {

        Button1.Attributes["onclick"] = "PushCheckItems(a);";

        if (!Page.IsPostBack)
        {
            string sql = "";
            string connstr = System.Configuration.ConfigurationManager.AppSettings["DataSQL"];

            DB cDB = new DB();

            sql = "select * from mztree";

            DataTable DT = cDB.RunSQLGetDT(sql, connstr);

            if (DT.Rows.Count > 0)
            {

                tree = tree + "<nodes>";

                treeone = "data[’-1_0’] = ’text: 梅花雪树;’;";

                nodeBinding(DT, "0");

                tree = tree + "</nodes>";
            }
        }

    }


    public void nodeBinding(DataTable _dt, string _filter)
    {
        string sFilter = "pid=" + _filter;

        DataView dv = new DataView(_dt);

        dv.RowFilter = sFilter;

        if (dv.Count > 0)
        {
            foreach (DataRowView drv in dv)
            {
                tree = tree + "<node id=’" + drv["ID"].ToString() + "’ text=’" + drv["name"].ToString() + "’>";

                nodeBinding(_dt, drv["ID"].ToString());

                tree = tree + "</node>";
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write(hfChecked.Value);
        Response.End();
    }
}


梅花雪js树2.0版本带checkbox获取选中值例子,[asp.net基础]

上一篇:JS面试题①


下一篇:C#连接数据库方式,Access,SQL Server,Oracle,MySQL,IBM DB2 ,SyBase,excel等,[bubufx分享asp.net基础]