问题描述
表的结构是这样的:id(主键)TreeParentIDTreeName10aa21aa31aa41aa51aa61aa....我用这种数据结构做了无限级树型菜单(增加,修改,删除)。我想把这种数据结构改成无限连动(下拉菜单)。有什么好办法吗?最好是无刷新的,高分跪求!
解决方案
解决方案二:
用ajax可以实现的。
解决方案三:
可以用JS来实现!!你找找代码!很多的!
解决方案四:
非ajax莫属.推荐prototype包装类
解决方案五:
createtableTree([id]intprimarykeyidentity(1,1),[TreeParentID]int,[TreeName]varchar(50))insertintoTree(TreeParentID,TreeName)values(0,'aa')insertintoTree(TreeParentID,TreeName)values(1,'bb')insertintoTree(TreeParentID,TreeName)values(1,'bb')insertintoTree(TreeParentID,TreeName)values(2,'cc')insertintoTree(TreeParentID,TreeName)values(2,'cc')insertintoTree(TreeParentID,TreeName)values(3,'dd')insertintoTree(TreeParentID,TreeName)values(3,'dd')
Tree.aspx<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Tree.aspx.cs"Inherits="Tree"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title></head><body><formid="form1"runat="server"><div><asp:TreeViewID="TreeView1"runat="server"></asp:TreeView> </div></form></body></html>
Tree.axpx.csusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclassTree:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){stringsqlstr=ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;SqlConnectionconn=newSqlConnection(sqlstr);SqlCommandcmd=newSqlCommand();DataSetds=newDataSet();cmd.CommandText="select*fromTree";SqlDataAdapterda=newSqlDataAdapter();cmd.Connection=conn;da.SelectCommand=cmd;da.Fill(ds);BindTreeView(ds.Tables[0]);}#regionBindTreeView//邦定根节点publicvoidBindTreeView(DataTabledt){DataRow[]drs=dt.Select("TreeParentID="+0);// 选出所有子节点TreeView1.Nodes.Clear();//清空树for(inti=0;i<Convert.ToInt32(drs.Length);i++){DataRowr=drs[i];stringnodeid=r["id"].ToString();stringtext=r["TreeName"].ToString();stringparentid=r["TreeParentID"].ToString();//treeviewsetthis.TreeView1.Font.Name="宋体";this.TreeView1.Font.Size=FontUnit.Parse("9");TreeNoderootnode=newTreeNode();rootnode.Text=text;rootnode.Value=nodeid;rootnode.SelectAction=TreeNodeSelectAction.Expand;//和ASP.NET1.1中TREEVIEW的SelectExpands属性等效TreeView1.Nodes.Add(rootnode);intsonparentid=int.Parse(nodeid);//or=locationCreateNode(sonparentid,rootnode,dt);}}//邦定任意节点publicvoidCreateNode(intparentid,TreeNodeparentnode,DataTabledt){DataRow[]drs=dt.Select("TreeParentID="+parentid);//选出所有子节点for(inti=0;i<Convert.ToInt32(drs.Length);i++){DataRowr=drs[i];stringnodeid=r["id"].ToString();stringtext=r["TreeName"].ToString();TreeNodenode=newTreeNode();node.Text=text;node.Value=nodeid;node.SelectAction=TreeNodeSelectAction.Expand;//和ASP.NET1.1中TREEVIEW的SelectExpands属性等效intsonparentid=int.Parse(nodeid);//or=locationif(parentnode==null){TreeView1.Nodes.Clear();parentnode=newTreeNode();TreeView1.Nodes.Add(parentnode);}parentnode.ChildNodes.Add(node);CreateNode(sonparentid,node,dt);}//endforeach}#endregion}
解决方案六:
ajax
解决方案七:
mark好东西!
解决方案八:
用递归把一个父id设为0掉用时直接dlltb(0);///<summary>///返回要的datatable///</summary>///<paramname="ParentId"></param>///<returns></returns>privateDataTabledlltb(intParentId){stringstr="select*from你的表名字whereTreeParentID="+ParentId;DataSetds=DbHelperSQL.Query(str);DataTabledt=newDataTable();DataColumndc=newDataColumn();dc=newDataColumn("id",typeof(System.Int32));dt.Columns.Add(dc);dc=newDataColumn("TreeName",typeof(System.String));dt.Columns.Add(dc);for(inti=0;i<ds.Tables[0].Rows.Count;i++){DataRowrows=dt.NewRow();rows.ItemArray=newobject[]{Convert.ToInt32(ds.Tables[0].Rows[i]["id"]),ds.Tables[0].Rows[i]["TreeName"].ToString()};dt.Rows.Add(rows);DataTabletbb=dlltb(Convert.ToInt32(ds.Tables[0].Rows[i]["id"]));for(intj=0;j<tbb.Rows.Count;j++){DataRowrow=dt.NewRow();row.ItemArray=newobject[]{tbb.Rows[j]["id"].ToString(),tbb.Rows[j]["TreeName"].ToString()};dt.Rows.Add(row);}}dt.AcceptChanges();returndt;}
解决方案九:
要是想无限级下拉的话那你还得动态生成DROPDOWNLIST啊。。。?
解决方案十:
该回复于2007-12-04 11:19:39被版主删除
解决方案十一:
AJAX可以实现的。上面已经给出代码了
解决方案十二:
呵呵,我自己写了个,楼主需要的话,联系我
解决方案十三:
不建议一次递归完,我也做了个和你的表结构一样,有一千多条记录,造成数据库连接池已满,第一次优化出来的HTML文件有1兆多后来又优化了一下,效果很不错,点哪刷哪,和一次绑定的感觉一样无刷新跟程序没关系啊,用他们说的控件就OK了
解决方案十四:
mark,study,up.
解决方案十五:
使用递归生成树形结构publicvoidInitTree(TreeNodeCollectionNds,stringD_belong_ID){TreeNodeNewNode;//data为存储建树数据信息的数据集//用父节点进行筛选数据集中信息'DataRow[]rows=data.Tables[0].Select("D_belong_ID='"+D_belong_ID+"'");foreach(DataRowrowinrows){/*NewNode=newTreeNode("<labelid='lm"+row[0].ToString()+"'><aid='m"+row[0].ToString()+"'onFocus='getfocus()'onBlur='unfocus()'onmouseover=TreeView_left(0,'m"+row[0].ToString()+"');onmouseout=TreeView_left(1,'m"+row[0].ToString()+"');>"+row[1].ToString()+"</a></label>",row[0].ToString(),"","http://www.163.com/?id="+row[0].ToString(),"_blank");*/NewNode=newTreeNode("<inputclass=nofocustype=buttonname=m"+row[0].ToString()+"value="+row[2].ToString()+"id=m"+row[0].ToString()+"onBlur=lostfocus('m"+row[0].ToString()+"')onmouseover=TreeView_left(0,'"+row[6].ToString()+"','"+row[0].ToString()+"','m"+row[0].ToString()+"')onmouseout=TreeView_left(1,'"+row[6].ToString()+"','"+row[0].ToString()+"','m"+row[0].ToString()+"')/>");Nds.Add(NewNode);InitTree(NewNode.ChildNodes,row[0].ToString());}}
解决方案:无刷新和程序没有关系????要实现无刷新还是要用ajax,后台方法已经给出了。