类似 MSDN 导航树效果 ASP.Net(C#) + JavaScript 实现! (转)[@more@]
WebFORM1
microsoft Visual Studio 7.0">
Javascript">
intellisense/ IE5">
RM id="FORM1" method="post" runat="server">
WebFORM2
Javascript">
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 nSpace = nSpace + " ";
string sHTML ="";
i=0;
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=TRIATONPSQL2KE";
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 parentid = " + Request.QueryString["PID"],oleDbConnection1) ;
System.Data.OleDb.OleDbDataReader OleDbDataReader1 = OleDbCommand1.ExecuteReader();
while (OleDbDataReader1.Read())
{
sHTML = sHTML + "
if (System.Convert.ToInt64(OleDbDataReader1["children"])>0)
sHTML = sHTML + "
i++;
}
Response.Write(sHTML);
%>
测试站点:
do.NET/tree/webFORM1.ASPx">http://www.triaton.com.cn/../dotnet/tree/WebFORM1.aspx
虽然号称 .net 了!
但实际还是传统 CGI、ASP 的思想,没有使用Codebehind="WebFORM1.aspx.cs",仍然采取了 B/S 混合(HTML/C#)脚本的方式:
A href="tag-88-1.html">w3c//DTD HTML 4.0 Transitional//EN" >
WebFORM1
microsoft Visual Studio 7.0">
Javascript">
intellisense/ IE5">
RM id="FORM1" method="post" runat="server">
|
WebFORM2
Javascript">
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 nSpace = nSpace + " ";
string sHTML ="";
i=0;
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=TRIATONPSQL2KE";
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 parentid = " + Request.QueryString["PID"],oleDbConnection1) ;
System.Data.OleDb.OleDbDataReader OleDbDataReader1 = OleDbCommand1.ExecuteReader();
while (OleDbDataReader1.Read())
{
sHTML = sHTML + "
" + nSpace + "
if (System.Convert.ToInt64(OleDbDataReader1["children"])>0)
sHTML = sHTML + " onClick='ExpandNode(" + ParentNode + "_" + (i + 1).ToString() + "," + OleDbDataReader1["id"] + ")'>+";
else
sHTML = sHTML + ">-";
sHTML = sHTML + "n" + " if (System.Convert.ToInt64(OleDbDataReader1["children"])>0)
sHTML = sHTML + " onDblClick='ExpandNode(" + ParentNode + "_" + (i + 1).ToString() + "," + OleDbDataReader1["id"] + ")'";
sHTML = sHTML + ">" + OleDbDataReader1["id"] + ": " + OleDbDataReader1["remark"] + "
";
sHTML = sHTML + " onClick='ExpandNode(" + ParentNode + "_" + (i + 1).ToString() + "," + OleDbDataReader1["id"] + ")'>+";
else
sHTML = sHTML + ">-";
sHTML = sHTML + "n" + " if (System.Convert.ToInt64(OleDbDataReader1["children"])>0)
sHTML = sHTML + " onDblClick='ExpandNode(" + ParentNode + "_" + (i + 1).ToString() + "," + OleDbDataReader1["id"] + ")'";
sHTML = sHTML + ">" + OleDbDataReader1["id"] + ": " + OleDbDataReader1["remark"] + "
if (System.Convert.ToInt64(OleDbDataReader1["children"])>0)
sHTML = sHTML + "
" + nSpace + " 正在加载 ...
";
i++;
}
Response.Write(sHTML);
%>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-998325/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10748419/viewspace-998325/