小弟要做一个树形目录,请各位帮忙?谢谢了

liuvb 2003-10-19 05:26:37
最好能完整一点的,(c#),谢谢各位。
...全文
88 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
terry2003 2003-10-21
  • 打赏
  • 举报
回复
up
s3p 2003-10-21
  • 打赏
  • 举报
回复
up
feixiang1234 2003-10-21
  • 打赏
  • 举报
回复
tree.aspx.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;
using System.Data.SqlClient;


namespace newsplay.admin_news
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class tree : System.Web.UI.Page
{
protected static string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
System.Data.SqlClient.SqlConnection SqlConn=new System.Data.SqlClient.SqlConnection(ConnectionString);
SqlCommand SqlComm=new SqlCommand();
private void Page_Load(object sender, System.EventArgs e)
{
Begin();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

void BuildTree(int pid,int level)
{
level++;
SqlComm.Connection=SqlConn;
SqlComm.CommandText="select * from NewsTypeCode where sign=0 and parentid="+pid+"order by id";
SqlDataAdapter sda=new SqlDataAdapter(SqlComm);
DataSet ds=new DataSet();
sda.Fill(ds);
int cols=ds.Tables[0].Rows.Count;
for(int i=0;i<cols;i++)
{
Response.Write("<div>");
for(int j=0;j<level;j++)
Response.Write("---");
if(has_child(int.Parse(ds.Tables[0].Rows[i][0].ToString())))
{
Response.Write("<img alt=\"展开\" style=\"cursor:hand;\"onclick=\"myClick("+int.Parse(ds.Tables[0].Rows[i][0].ToString())+");\"id=\"img"+int.Parse(ds.Tables[0].Rows[i][0].ToString())+"\" src=\"images\\plus.ico\"> <img id=\"im"+int.Parse(ds.Tables[0].Rows[i][0].ToString())+"\"src=\"images\\closedfold.ico\">");
Response.Write("<span onclick=\"myClick1("+int.Parse(ds.Tables[0].Rows[i][0].ToString())+");\"style=\"cursor:default;\"id=\"span"+int.Parse(ds.Tables[0].Rows[i][0].ToString())+"\">"+"<a href=\"javascript:opener.document.form1.newstype.value='"+ds.Tables[0].Rows[i][1].ToString()+"';javascript:opener.document.form1.newstype1.value='"+ds.Tables[0].Rows[i][0].ToString()+"';window.close();\">"+ds.Tables[0].Rows[i][1].ToString()+"</a></span>");
Response.Write("<div style=\"display:none;\" id=\"div"+int.Parse(ds.Tables[0].Rows[i][0].ToString())+"\">");
BuildTree(int.Parse(ds.Tables[0].Rows[i][0].ToString()),level);//递归调用
Response.Write("</div>");
}
else
Response.Write("<img src=\"images\\minus.ico\"> <img src=\"images\\openfold.ico\"> <span onclick=\"myClick1('"+int.Parse(ds.Tables[0].Rows[i][0].ToString())+"\">"+"<a href=\"javascript:opener.document.form1.newstype.value='"+ds.Tables[0].Rows[i][1].ToString()+"';javascript:opener.document.form1.newstype1.value='"+ds.Tables[0].Rows[i][0].ToString()+"';window.close();\">"+ds.Tables[0].Rows[i][1].ToString()+"</a></span>");
Response.Write("</div>");
}
SqlConn.Close();
SqlComm.Dispose();
ds.Clear();
sda.Dispose();
}
public bool has_child(int pid)
{
SqlComm.Connection=SqlConn;
SqlComm.CommandText="select * from NewsTypeCode where sign=0 and parentid="+pid+"order by id";
SqlDataAdapter sda=new SqlDataAdapter(SqlComm);
DataSet ds=new DataSet();
sda.Fill(ds);
int col=ds.Tables[0].Rows.Count;
if(col>0)
return true;
else
return false;
}

void Begin()
{
Response.Write("<title>构造目录树</title>");
BuildTree(-1,0);
}
}
}
tree.aspx

<%@ Page language="c#" Codebehind="tree.aspx.cs" AutoEventWireup="false" Inherits="newsplay.admin_news.tree" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>树形目录</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form runat="server" ID="form1">
<FONT face="宋体"></FONT> </form>
<script language="JavaScript">
function myClick(id)
{
eval("var div=div"+id);
eval("var img=img"+id);
eval("var im=im"+id);
div.style.display=div.style.display!="none"?"none":"block";
img.src=div.style.display!="none"?"images\\minus.ico":"images\\plus.ico";
im.src=div.style.display!="none"?"images\\openfold.ico":"images\\closedfold.ico";
img.alt=div.style.display!="none"?"关闭":"展开";
}
function myClick1(id)
{
document.form1.parentid.value=id;
}
</script>
</body>
</HTML>
513 2003-10-20
  • 打赏
  • 举报
回复
建议到microsoft网站上去下。安装
liuvb 2003-10-20
  • 打赏
  • 举报
回复
我是双击,但是没有反应。
dongbeiren 2003-10-20
  • 打赏
  • 举报
回复
双击,和别的控件用法一样
liuvb 2003-10-20
  • 打赏
  • 举报
回复
我下了一个树形控件,也添加到工具箱里了,不知道为什么拖不到页面上。
cocoa2003 2003-10-20
  • 打赏
  • 举报
回复
下载一个树形控件就可以拉.帮助中还有这个控件的使用.
guoyan19811021 2003-10-20
  • 打赏
  • 举报
回复
www.ourfly.com中的例子
noahart 2003-10-19
  • 打赏
  • 举报
回复
up
ddangerous169 2003-10-19
  • 打赏
  • 举报
回复
lf
yuanylong 2003-10-19
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2093/2093882.xml?temp=.318722
rgbcn 2003-10-19
  • 打赏
  • 举报
回复
see

http://expert.csdn.net/Expert/topic/2156/2156791.xml?temp=.4683649

内容是

最近完善了拷贝和粘贴功能,不过拷贝还没有实现连同子结点一起拷贝
附带信息发布系统

http://www.fm119.com/admin2003/
user:admin
pass:admin

download url: http://www.fm119.com/admin2003/admin2003.rar
rgbcn 2003-10-19
  • 打赏
  • 举报
回复
Online Carpentry: Crafting a New MSDN Table of Contents
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwebgen/html/msdntoc.asp

C# code: (note, it uses BETA version of .NET, you need to make changes)
The MSDN Table of Contents in C#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml01152001.asp
rgbcn 2003-10-19
  • 打赏
  • 举报
回复
类似 MSDN CSDN 导航树效果 ASP.Net(C#)

http://www.ceocio.net/article_view.asp?bigtypeid=2&smalltypeid=5&id=43

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧