• 梅花雪2.0树数据库数据绑定实例(vs2010)


    梅花雪2.0树型结构sqlserver数据库数据绑定,IDE是VS2010,数据库是sql server2005,部分代码如下,代码实例【点击这里】下载。

    效果图

    数据库结构代码:

    CREATE TABLE [mzTree](
        [ID] [int] IDENTITY(1,1NOT NULL,
        [name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
        [pid] [int] NULL
    )

    mztree.aspx:

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

    <html>
    <head runat="server">
        <title></title>
        <script src="treescripts/jsframework.js" type="text/javascript"></script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table width="500" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="50">
                        &nbsp;
                    </td>
                    <td>
                        <div style=" 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 
    = false
                            a.canOperate 
    = true;
                            document.write(a.render());
                            a.expandLevel(
    6);
                            
    //*/

                            
    </script>
                        </div>
                    </td>
                    <td width="50">
                        &nbsp;
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>

    mztree.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 : System.Web.UI.Page
    {

        public string tree = "";
        public string treeone = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            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() + "' url='testurl.aspx?id=" + drv["ID"].ToString() + "' target='_blank'>";

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

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

    }
  • 相关阅读:
    vue路由篇(动态路由、路由嵌套)----动态路由下再嵌套子路由
    文件、I/O重定向、文本
    Linux基础命令
    Chrome开发者工具(DevTools)使用技巧
    Grid网格布局知识点整理
    Javascript常见数组、字符串API整理
    css 实现瀑布流布局效果
    实时校验输入框内容
    app里遇见的小问题总结
    修复bug: iOS特性会滚动会引起白屏 ,使用 will-change: transform;
  • 原文地址:https://www.cnblogs.com/weekzero/p/2579245.html
Copyright © 2020-2023  润新知