软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络编程 > ASP.NET > zTree在asp.net中读取数据库简单使用示例

zTree在asp.net中读取数据库简单使用示例

原来使用的TreeView控件,感觉很麻烦。今天用zTree替换了一下,感觉不错,清晰多了,而且可以跨平台。

HTML代码:

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="zTreeTest.aspx.cs" Inherits="zTreeTest" %>

<!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>
<link href="css/zTree/demoStyle/demo.css" rel="stylesheet" type="text/css" />
<link href="css/zTree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="js/jquery.ztree-2.6.js" type="text/javascript"></script>
<script type="text/javascript">
var zTreeObj;
var setting = {checkable: true};
var zNodes = <%= seriesData.ToString() %>;

$(document).ready(function () {
zTreeObj = $("#treeDemo").zTree(setting, zNodes);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="zTreeDemoBackground">
<ul id="treeDemo" class="tree"></ul>
</div>
</form>
</body>
</html>

数据库配置就不发布了,大家按照自己的配置能读数据库即可:

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com]
using System;
using System.Data;
using System.Text;

public partial class zTreeTest : System.Web.UI.Page
{
public StringBuilder seriesData = new StringBuilder();

public connCls conncls;
public Global glb;
public DataSet ds1;
public DataSet ds2;
public DataSet ds3;
public DataSet ds4;

protected void Page_Load(object sender, EventArgs e)
{
conncls = new connCls();
glb = new Global();

string cmdstr = "";
string name="";
string no="";
cmdstr = "select * from region";
ds1 = glb.getDS(conncls.getconnstr(), cmdstr);
seriesData.Append("[");
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
seriesData.Append("{");
name=ds1.Tables[0].Rows[i]["region_name"].ToString();
seriesData.Append("name:\""+name+"\"");
seriesData.Append(",");
no=ds1.Tables[0].Rows[i]["region_no"].ToString();
seriesData.Append("no:"+no);
seriesData.Append(",");

cmdstr = "select * from building where region_no='"+no+"'";
ds2 = glb.getDS(conncls.getconnstr(), cmdstr);
seriesData.Append("nodes:[");
for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
{
seriesData.Append("{");
name = ds2.Tables[0].Rows[j]["building_name"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds2.Tables[0].Rows[j]["building_no"].ToString();
seriesData.Append("no:" + no);
seriesData.Append(",");

cmdstr = "select * from cell where building_no='" + no + "'";
ds3 = glb.getDS(conncls.getconnstr(), cmdstr);
seriesData.Append("nodes:[");
for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
{
seriesData.Append("{");
name = ds3.Tables[0].Rows[k]["cell_name"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds3.Tables[0].Rows[k]["cell_no"].ToString();
seriesData.Append("no:" + no);
seriesData.Append(",");

cmdstr = "select * from house where cell_no='" + no + "'";
ds4 = glb.getDS(conncls.getconnstr(), cmdstr);
seriesData.Append("nodes:[");
for (int l = 0; l < ds4.Tables[0].Rows.Count; l++)
{
seriesData.Append("{");
name = ds4.Tables[0].Rows[l]["house_name"].ToString();
seriesData.Append("name:\"" + name + "\"");
seriesData.Append(",");
no = ds4.Tables[0].Rows[l]["house_no"].ToString();
seriesData.Append("no:" + no);
seriesData.Append("}");

if (l != ds4.Tables[0].Rows.Count - 1)
{
seriesData.Append(",");
}
}
seriesData.Append("]}");
if (k != ds3.Tables[0].Rows.Count - 1)
{
seriesData.Append(",");
}
}
seriesData.Append("]}");
if (j != ds2.Tables[0].Rows.Count - 1)
{
seriesData.Append(",");
}
}
seriesData.Append("]}");
if (i != ds1.Tables[0].Rows.Count - 1)
{
seriesData.Append(",");
}
}
seriesData.Append("]");
}
}

演示图:

    相关阅读
    栏目导航
    推荐软件