asp.net2.0中treeview缓存绑定问题
在csdn上看到很多关于TREEVIEW动态绑定的帖子,无非就是递归算法之类....==
现在看一个问题
1000
1001
1011
....
...
1012
.....
1002
1021
.....
1022
1003
1031
1032
2000
2001
2011
2012
2002
....
2003
....
2004
3000
3001
3002
3003
4...
.....
.....
.
.
.
.
..
或数据库中也有类似分类
当深度很少的时候和接点少的时候在页面LOAD时动态绑顶似乎很可以
但是当接点很多的或深度很大时候(类似绑顶磁盘目录)这样在页面加载的时候很浪费时间
现在我就拿上面的例子问问
我想在当1000要展开时候只把1001 1002 1003 (显示出来)绑顶 其子(1001 1002 1003)结点不绑顶,只有当1001要展开的时候在把他的子结点再绑定,这样就没必要把所有数据在page_load时候都读出来了,而是等你想展开的那个结点要展开时候只显示他的下一级结点,不展开的结点不进行数据绑定,这样在页面加载的时候就不要把数据库中全部数据都读出来了(尤其是当数据库很大时候这个方法很有效),我上学的时候我老师在课上就做过TREVIEW绑顶磁盘目录的例子,用这个方法很节省时间,但是我都忘了。
谁知道这种方法怎么实现?
我先在这谢谢 了!~~
[解决办法]
asp.net示例:
using System;using System.Data;using System.Data.OleDb;using System.Configuration;using System.Collections;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 DataProvider;using WavenetWebFrameWork.FrameWorkBase.PageBase;namespace WaveDBMS{ public partial class NewMenu : System.Web.UI.Page { #region ARGS private TreeNode[] treF, treC,treGs; private TreeNode treG; private string[] strF, strC,strCL,strGs,strGsL; private string strCon,strDBType,strUID; protected DataProviderFactory dpf; private string strSqlF, strSqlC, strSqlGs; private DataTable dtF,dtC,dtGs; private int intFRowsLength, intCRowsLength, intGsRowsLength; PageBase pb = new PageBase(); public string UserID { get { return strUID; } set { strUID = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { strCon = System.Configuration.ConfigurationSettings.AppSettings.Get("UserAppData"); strDBType = System.Configuration.ConfigurationSettings.AppSettings.Get("UserAppDataType"); strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + strCon + "\";Persist Security Info=True"; strCon = pb.userappdata; dpf = new DataProviderFactory(strDBType, strCon, ""); strUID = "1"; if(!IsPostBack) { treG = new TreeNode(); treG.Text = "排水行业数据库"; treG.ImageUrl = "~/Images/database1.gif"; this.TreeV.Nodes.Add(treG); this.BuildTrees(); } } protected void BuildTrees() { strSqlF = "SELECT ID,MENUNAME,LINKURL FROM MENU WHERE PARENTID=-1"; String strSqlF4 = ""; strSqlF4 = "SELECT MENU.ID AS AA,MENU.MENUNAME AS BB,MENU.LINKURL AS CC,MENU.PARENTID AS DD "; strSqlF4 += " FROM MENU,RULES,ROLE2RULE "; strSqlF4 += " WHERE MENU.ID = RULES.MENUID "; strSqlF4 += " AND RULES.RULEID = ROLE2RULE.RULEID"; strSqlF4 += " AND ROLE2RULE.ROLEID = "+strUID ; strSqlF4 += " AND ROLE2RULE.RULEACTIONVALUE=1"; //strSqlF = "SELECT MENU2.AA,MENU2.BB,MENU2.CC,MENU2.DD FROM (" + strSqlF4 + ") MENU2 WHERE MENU2.DD=-1"; dtF = dpf.GetData(strSqlF); intFRowsLength = dtF.Rows.Count; if (intFRowsLength < 1) { return; } strF = new string[intFRowsLength]; treF = new TreeNode[intFRowsLength]; for (int i = 0; i < intFRowsLength ; i++) { strF[i] = dtF.Rows[i][1].ToString(); treF[i] = new TreeNode(); treF[i].Text=strF[i]; treF[i].CollapseAll(); treF[i].ImageUrl = "~/Images/database2.gif"; this.treG.ChildNodes.Add(treF[i]); ////////////////// strSqlC = "SELECT ID,MENUNAME,LINKURL FROM MENU WHERE PARENTID=" + dtF.Rows[i][0].ToString(); //strSqlC = "SELECT MENU2.AA,MENU2.BB,MENU2.CC,MENU2.DD FROM (" + strSqlF4 + ") MENU2 WHERE MENU2.DD=" + dtF.Rows[i][0].ToString(); dtC = dpf.GetData(strSqlC); intCRowsLength = dtC.Rows.Count; strC = new string[intCRowsLength]; strCL = new string[intCRowsLength]; treC = new TreeNode[intCRowsLength]; for (int j = 0; j < intCRowsLength ; j++) { strSqlGs = "SELECT ID,MENUNAME,LINKURL FROM MENU WHERE PARENTID=" + dtC.Rows[j][0].ToString(); dtGs = dpf.GetData(strSqlGs); intGsRowsLength = dtGs.Rows.Count; strC[j] = dtC.Rows[j][1].ToString(); strCL[j] = dtC.Rows[j][2].ToString(); treC[j] = new TreeNode(); treC[j].CollapseAll(); treC[j].Text = strC[j]; treC[j].NavigateUrl = strCL[j]; treC[j].Target = "MainData"; treC[j].ImageUrl = "~/Images/database3.gif"; if (intGsRowsLength>0) { treC[j].ImageUrl = "~/Images/database2.gif"; } treF[i].ChildNodes.Add(treC[j]); ///// if (intGsRowsLength == 0) { continue; } strGs = new string[intGsRowsLength]; strGsL = new string[intGsRowsLength]; treGs = new TreeNode[intGsRowsLength]; for (int h = 0; h < intGsRowsLength; h++) { strGs[h] = dtGs.Rows[h][1].ToString(); strGsL[h] = dtGs.Rows[h][2].ToString(); treGs[h] = new TreeNode(); treGs[h].Text = strGs[h]; treGs[h].NavigateUrl = strGsL[h]; treGs[h].Target = "MainData"; treGs[h].ImageUrl = "~/Images/database3.gif"; treC[j].ChildNodes.Add(treGs[h]); } } } } }}
[解决办法]
应该说,你的动态加载节点的观念描述还是挺到位的。关键就是教材选择问题。csdn只是一个获取信息的地方,你不能把“在csdn上看到很多关于......,无非就是.....之类....”太当回事。csdn上涉及的asp.net开发知识不足20%,剩下的80%靠你自己去找asp.net真正机制的资料。