asp.net用TreeView后台动态生成节点,怎么实现点击节点就在有框架中打开相应页面
页面中有左右两个框架,左边是显示菜单,我用TreeView在后台添加节点,那要怎么实现我上面标题讲的那样。或者说在后台怎么给节点添加点击事件,触发脚本。...
页面中有左右两个框架,左边是显示菜单,我用TreeView在后台添加节点,那要怎么实现我上面标题讲的那样。或者说在后台怎么给节点添加点击事件,触发脚本。
展开
展开全部
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Collections.Generic;
/// <summary>
/// WriteSchoolMenu 的摘要说明
/// </summary>
public class WriteSchoolMenu
{
StringBuilder sb = new StringBuilder();
public bool WriteSchoolTree(int sid,int rid)
{
try
{
//基本算法
string strname = new HTMLFileName().FileName(CommonTool.Check.GetInt32(rid));
sb.Append("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
sb.Append("<html xmlns='http://www.w3.org/1999/xhtml' >");
sb.Append("<head>");
sb.Append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />");
sb.Append("<title>树形</title>");
sb.Append("<link href='../../../../jquery/jquery.treeview.css' rel='stylesheet' type='text/css' />");
sb.Append("<script src='../../../../jquery/jquery-1.3.2.min.js'></script>");
sb.Append("<script src='../../../../jquery/jquery.treeview.js'></script>");
sb.Append("<script>window.onload = (function(){try{$('#example').treeview({collapsed: true});}catch(e){}});</script>");
sb.Append("<style>html,body{border:0; margin:0; padding:0;font-size:14px; color:#000066;}</style>");
sb.Append("</head>");
sb.Append("<body> <ul id='example'>");
Tree_menu(sid,rid,0);
sb.Append("</ul>");
sb.Append("</body>");
sb.Append("</html>");
Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("~/html/school/School_" + sid + "/tree/"));
string filename = System.Web.HttpContext.Current.Server.MapPath("~/html/school/School_" + sid + "/tree/" + strname + ".html");
//FileStream filstr = new FileStream(filename,FileMode.Create);
StreamWriter sw = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(sb.ToString());
sw.Close();
sw.Dispose();
return true;
}
catch (Exception ex)
{
return false;
}
}
private void Tree_menu(int sid,int rid,int P_ID)
{
DataTable dt = new BLL.ViewSchoolMenInfo().GetMenuBySidPid(sid,P_ID,rid);
if (dt.Rows.Count <= 0)
return;
if (dt.Rows.Count >= 1)
sb.Append("<UL>");
foreach (DataRow dr in dt.Rows)
{
if (CommonTool.Check.GetInt32(dr["parentid"]) == P_ID)
{
sb.Append("<li>" + "<a href='../../../../" + dr["noteURL"] + "' target='main'>" + dr["rightname"].ToString() + "</a>");
Tree_menu(sid,rid,CommonTool.Check.GetInt32(dr["id"]));
sb.Append("</li>");
}
}
if (dt.Rows.Count >= 1)
sb.Append("</UL>");
}
}
我做的可能比较复杂,简而言之就是生成静态html页面的过程中给节点添加对应的href链接地址,希望对你有帮助!
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Collections.Generic;
/// <summary>
/// WriteSchoolMenu 的摘要说明
/// </summary>
public class WriteSchoolMenu
{
StringBuilder sb = new StringBuilder();
public bool WriteSchoolTree(int sid,int rid)
{
try
{
//基本算法
string strname = new HTMLFileName().FileName(CommonTool.Check.GetInt32(rid));
sb.Append("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
sb.Append("<html xmlns='http://www.w3.org/1999/xhtml' >");
sb.Append("<head>");
sb.Append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />");
sb.Append("<title>树形</title>");
sb.Append("<link href='../../../../jquery/jquery.treeview.css' rel='stylesheet' type='text/css' />");
sb.Append("<script src='../../../../jquery/jquery-1.3.2.min.js'></script>");
sb.Append("<script src='../../../../jquery/jquery.treeview.js'></script>");
sb.Append("<script>window.onload = (function(){try{$('#example').treeview({collapsed: true});}catch(e){}});</script>");
sb.Append("<style>html,body{border:0; margin:0; padding:0;font-size:14px; color:#000066;}</style>");
sb.Append("</head>");
sb.Append("<body> <ul id='example'>");
Tree_menu(sid,rid,0);
sb.Append("</ul>");
sb.Append("</body>");
sb.Append("</html>");
Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("~/html/school/School_" + sid + "/tree/"));
string filename = System.Web.HttpContext.Current.Server.MapPath("~/html/school/School_" + sid + "/tree/" + strname + ".html");
//FileStream filstr = new FileStream(filename,FileMode.Create);
StreamWriter sw = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(sb.ToString());
sw.Close();
sw.Dispose();
return true;
}
catch (Exception ex)
{
return false;
}
}
private void Tree_menu(int sid,int rid,int P_ID)
{
DataTable dt = new BLL.ViewSchoolMenInfo().GetMenuBySidPid(sid,P_ID,rid);
if (dt.Rows.Count <= 0)
return;
if (dt.Rows.Count >= 1)
sb.Append("<UL>");
foreach (DataRow dr in dt.Rows)
{
if (CommonTool.Check.GetInt32(dr["parentid"]) == P_ID)
{
sb.Append("<li>" + "<a href='../../../../" + dr["noteURL"] + "' target='main'>" + dr["rightname"].ToString() + "</a>");
Tree_menu(sid,rid,CommonTool.Check.GetInt32(dr["id"]));
sb.Append("</li>");
}
}
if (dt.Rows.Count >= 1)
sb.Append("</UL>");
}
}
我做的可能比较复杂,简而言之就是生成静态html页面的过程中给节点添加对应的href链接地址,希望对你有帮助!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询