日期:2011-06-09  浏览次数:20545 次

asp.net带的TreeView有几个缺点:

1,有的浏览器不能够正确显示树,就是ie6有的也不能够正常显示

2,速度慢,老牛拉破车啊,慢的不得了

所以我就找了个js树,数据库版的,但那是asp的,没办法,把他改成aspx的吧!!!

梅花树的资料:开发文档: http://www.meizz.com/Web/Article.asp?id=436
控件下载: http://www.meizz.com/Web/Download/MzTreeView10.rar
应用示例: http://www.meizz.com/Web/Demo/MzTreeView10.htm

更多细节:http://community.csdn.net/Expert/topic/3841/3841740.xml?temp=.3988459

特别感谢:久久的宝贝!!!!!

left.aspx代码如下:

 <script language="JavaScript" src="MzTreeView10.js"></script>
<link href="menutree/menu.css" type="text/css" rel="stylesheet">
<style> A.MzTreeview { PADDING-LEFT: 3px; FONT-SIZE: 12px } </style>
</HEAD>
<body leftmargin="0" topmargin="2">
<SCRIPT LANGUAGE="JavaScript">
window.tree = new MzTreeView("tree");
tree.setIconPath("menutree/"); //可用相对路径
<%=str%> //这里的str是在后台定义的一个string,他包含了从数据库取出来的所有节点信息,只能够写这里
//tree.setURL("Catalog.asp");
//tree.setTarget("MzMain");
document.write(tree.toString()); //亦可用 obj.innerHTML = tree.toString();
tree.focus(111); //让id是111的节点获得焦点,同时也展开了这个节点上的父节点!
//-->
</SCRIPT>
</body>

 

现在是后台cs文件:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace hualong.bbs
{
/// <summary>
/// left 的摘要说明。
/// </summary>
public class left : System.Web.UI.Page
{

public string str;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string connectstring = System.Configuration.ConfigurationSettings.AppSettings["connStr1"].ToString();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectstring);
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter("select_treeview_pwqzc",conn);
try
{
System.Text.StringBuilder node = new System.Text.StringBuilder();
conn.Open();
System.Data.DataSet dataset = new System.Data.DataSet();
dataset.Tables.Add("treeview");
adapter.Fill(dataset,"treeview");
foreach(System.Data.DataRow row in dataset.Tables[0].Rows)
{
node.Append("\r\n tree.nodes[\""+ row["parentId"].ToString() + "_" + row["id"] + "\"] = \"");
node.Append("text:" + row["text"].ToString().Replace("\0xE",";") + ";");
node.Append(row["hint"] != DBNull.Value && row["hint"].ToString() != string.Empty ? "hint:" + row["hint"].ToString().Replace("\0xE",";") + ";" : string.Empty);
node.Append(row["icon"] != DBNull.Value && row["icon"].ToString() != string.Empty ? "icon:" + row["icon"].ToString().Replace("\0xE",";") + ";" : string.Empty);
node.Append(row["data"] != DBNull.Value && row["data"].ToString() != string.Empty ? "data:" + row["data"].ToString().Replace("\0xE",";") +Server.UrlEncode(row["text"].ToString())+ ";" : string.Empty);
node.Append(row["url"] != DBNull.Value && row["url"].ToString() != string.Empty ? "url:" + row["url"].ToString().Replace("\0xE",";") + ";" : string.Empty);
node.Append(row["target"] != DBNull.Value && row["target"].ToString() != string.Empty ? "target:" + row["target"].ToString().Replace("\0xE",";") + ";" : string.Empty);
node.Append(row["method"] != DBNull.Value && row["method"].ToString() != string.Empty ? "method:" + row["me