高速的asp.net目录树源代码

作者:网络 来源:佚名 更新时间:2009-03-16 23:25:02 点击:


收集最实用的网页特效代码!

前台页面:

<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="tree._default" %>

<!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" language="javascript" src="mztreeview10.js"></script>
    <link href="css/global.css" type="text/css" rel="stylesheet"/>
    <style type="text/css">
        a.mztreeview
        {
            font-size: 9pt;
            padding-left: 3px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <script type="text/javascript" language="javascript">
    <!--
        window.tree = new mztreeview("tree");

        tree.icons["property"] = "property.gif";
        tree.icons["css"] = "collection.gif";
        tree.icons["book"]  = "book.gif";
        tree.iconsexpand["book"] = "bookopen.gif";
        tree.seticonpath("/images/");
        <% loadtree(); %>
        tree.seturl("#");
        tree.settarget("");
        document.write(tree.tostring()); 
    -->
    </script>
    </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.data.sql;
using system.data.sqlclient;
using treedemo.dbutility;

namespace tree
{
    public partial class _default : system.web.ui.page
    {
        public static string str;

        protected void page_load(object sender, eventargs e)
        {

        }

        public void loadtree()
        {          
            string sql = "select id,isnull(pid,0) as pid,caption from tree order by id";
            sqldatareader dr = treedemo.dbutility.sqlhelper.executereader(sqlhelper.connectionstring,commandtype.text, sql, null);
            string node = "";
            while(dr.read())
            {
                node = "\r\n     tree.nodes[" + "\"" + dr["pid"].tostring() + "_" + dr["id"].tostring() + "\"" + "] = ";
                node = node + "\"" + "text:" + dr["caption"].tostring() + ";" + "\"";
                response.write(node);
            }
            if (!dr.isclosed)
                dr.close();
        }
    }
}