类似 MSDN CSDN 导航树效果 ASP.Net(C#) + JavaScript 实现!

测试站点:
http://www.triaton.com.cn/../dotnet/tree/WebFORM1.aspx

虽然号称 .Net 了!
但实际还是传统 CGI、ASP 的思想,没有使用 Codebehind="WebFORM1.aspx.cs",仍然 采取了 B/S 混合(HTML/C#)脚本的方式:

1@ Page language="c#" Codebehind="WebFORM1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication5.WebFORM1" 
 1<html>
 2<head>
 3<title>WebFORM1</title>
 4<meta content="Microsoft Visual Studio 7.0" name="GENERATOR"/>
 5<meta content="C#" name="CODE_LANGUAGE"/>
 6<meta content="javascript" name="vs_defaultClientScript"/>
 7<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"/>
 8</head>
 9<body ms_positioning="GridLayout">
10<form id="FORM1" method="post" runat="server">
11</form>
12<font face="宋体"></font><iframe height="100" id="hiddenframe" width="100%"></iframe>
13<script>   
14function ExpandNode(ParentNode,ParentId){   
15var NodeX = eval(ParentNode.id + '_0');   
16if (NodeX.style.display == 'none')   
17{   
18NodeX.style.display="block";   
19if (NodeX.loaded == 'no')   
20{   
21document.frames['hiddenframe'].location.replace("http://localhost/webservice/WebApplication5/WebFORM2.aspx?PID=" + ParentId + "&PNode=" + ParentNode.id);   
22NodeX.loaded = 'yes';   
23}   
24}   
25else   
26{   
27NodeX.style.display='none';   
28}   
29}   
30</script>
31<center>
32<table border="1" height="60%" width="20%">
33<tr>
34<td>
35<div style="OVERFLOW: auto;WIDTH: 100%;HEIGHT: 100%">
36<table width="300%">
37<tr>
38<td>   

System.Data.OleDb.OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
oleDbConnection1.ConnectionString =@"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data Source=TRIATON\PSQL2KE";
oleDbConnection1.ConnectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/dvbbs") + @"\Tree.mdb;Persist Security Info=False";
oleDbConnection1.Open();
System.Data.OleDb.OleDbCommand OleDbCommand1 = new System.Data.OleDb.OleDbCommand("select ,(select count() from tree where parentid = T.id) as children from tree T where rootid = id",oleDbConnection1) ;
System.Data.OleDb.OleDbDataReader OleDbDataReader1 = OleDbCommand1.ExecuteReader();
int i = 0;
while (OleDbDataReader1.Read())
{

<div id="Node_ = i "><a (system.convert.toint64(oledbdatareader1["children"])="" ="" href="#" if="">0) {

1onClick='ExpandNode(Node_```
2 = i 
3```,```
4 =OleDbDataReader1["id"] 
5```)'&gt;+</a>   

;}
else {

1&gt;-```
2 ;}

<a (system.convert.toint64(oledbdatareader1["children"])="" ```="" href="#" if="">0)
{

1onDblClick='ExpandNode(Node_```
2 = i 
3```,```
4 =OleDbDataReader1["children"]
5```)'   

}

1&gt;   

=OleDbDataReader1["children"]

1</div>
2<div id="Node_```
3 = i 
4```_0" loaded="no" style="display: none">   
5正在加载 ...   
6</div>   

i++;
}

 1  
 2  
 3  
 4  
 5  
 6  
 7</td>
 8</tr></table></div></td>
 9</tr>
10</table>
11
12</center>
13</body>
14</html>
1@ Page language="c#" Codebehind="WebFORM2.aspx.cs" AutoEventWireup="false" Inherits="WebApplication5.WebFORM2" 
 1<html>
 2<head>
 3<title>WebFORM2</title>
 4<meta content="Microsoft Visual Studio 7.0" name="GENERATOR"/>
 5<meta content="C#" name="CODE_LANGUAGE"/>
 6<meta content="javascript" name="vs_defaultClientScript"/>
 7<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"/>
 8</head>
 9<body ms_positioning="GridLayout">
10<form id="WebFORM2" method="post" runat="server">
11<font face="宋体"></font>
12</form>   

string ParentNode;
ParentNode = Request.QueryString["pnode"];
//Response.Write(ParentNode.Replace("",""));
int i;
int j;
string nSpace="";
j= ParentNode.Length - ParentNode.Replace("
","").Length;
for (i=0;i<j;i++) "="" ";="" "<div="" (oledbdatareader1.read())="" )="" ,(select="" +="" ;="" @"\tree.mdb;persist="" as="" catalog="Test;Data" children="" count()="" dvbbs")="" from="" i="0;" id='" + ParentNode + "" + (i + 1).ToString() + "' info='False";' nspace="nSpace" oledbcommand1="new" oledbconnection1="new" oledbconnection1.connectionstring='@"Provider=Microsoft.Jet.OLEDB.4.0;Data' oledbconnection1.open();="" oledbdatareader1="OleDbCommand1.ExecuteReader();" parentid=" + Request.QueryString[" pid"],oledbconnection1)="" security="" shtml="sHTML" source=" + Server.MapPath(" string="" system.data.oledb.oledbcommand="" system.data.oledb.oledbcommand("select="" system.data.oledb.oledbconnection="" system.data.oledb.oledbconnection();="" system.data.oledb.oledbdatareader="" t="" tree="" where="" while="" {="">" + nSpace + "<a ";="" (system.convert.toint64(oledbdatareader1["children"])="" href="#" if="">0)
sHTML = sHTML + " onClick='ExpandNode(" + ParentNode + "
" + (i + 1).ToString() + "," + OleDbDataReader1["id"] + ")'&gt;+";
else
sHTML = sHTML + "&gt;-";
sHTML = sHTML + "</a>\\n" + "<a ";="" (system.convert.toint64(oledbdatareader1["children"])="" href="#" if="">0)
sHTML = sHTML + " onDblClick='ExpandNode(" + ParentNode + "" + (i + 1).ToString() + "," + OleDbDataReader1["id"] + ")'";
sHTML = sHTML + "&gt;" + OleDbDataReader1["id"] + ": " + OleDbDataReader1["remark"] + "</a>";
if (System.Convert.ToInt64(OleDbDataReader1["children"])&gt;0)
sHTML = sHTML + "<div id='" + ParentNode + "
" + (i + 1).ToString() + "_0' loaded="no" style="display: none">" + nSpace + " 正在加载 ...</div>";
i++;
}
Response.Write(sHTML);

 1<script>   
 2var x = eval('parent.' + '```
 3 =Request.QueryString["pnode"] + "_0"
 4```' ) ;   
 5x.innerHTML="```
 6 =sHTML 
 7```";   
 8</script>
 9</j;i++)></body>
10</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus