用C# + SqlServer2005 实现的treeview动态树形菜单
using System; using System.Data; 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 Syste
using System;
using System.Data;
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 System.Data.SqlClient;
public partial class TreeView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTV_Click(object sender, EventArgs e)
{
CreateTreeView(TreeView1.Nodes, "0");
}
/**/
///
/// 根据递归查询结果动态生成TreeView
///
private DataSet CreateDataSet()
{
string connetion = "database=test;server=.;uid=sa;pwd=sa123456;";
using (SqlConnection con = new SqlConnection(connetion))
{
SqlCommand com = new SqlCommand("select * from QuHua", con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds,"tree");
return ds;
}
}
///
/// 递归查询
///
/// TreeView的节点集合
/// 所属父级的ID
private void CreateTreeView(TreeNodeCollection nodes, string parentid)
{
DataView TempDV = new DataView();
TreeNode TempNode;
//string intId;
TempDV.Table = CreateDataSet().Tables["tree"];
TempDV.RowFilter = "ParentID=" + parentid + "";
foreach (DataRowView drv in TempDV)
{
TempNode = new TreeNode();
TempNode.Value = drv["TreeID"].ToString();
TempNode.Text = drv["TreeName"].ToString();
TempNode.NavigateUrl = drv["NodeUrl"].ToString();
nodes.Add(TempNode);
//intId = drv["ParentID"].ToString();
CreateTreeView(TempNode.ChildNodes, TempNode.Value);
}
}
}
上一篇: 请教TinkpPHP引用css样式问题
下一篇: ThinkPHP框架之实用项
推荐阅读
-
用C# + SqlServer2005 实现的treeview动态树形菜单
-
用C# + SqlServer2005 实现的treeview动态树形菜单
-
c#用Treeview实现FolderBrowerDialog 和动态获取系统图标(运用了Win32 dll类库)
-
c#用Treeview实现FolderBrowerDialog 和动态获取系统图标(运用了Win32 dll类库)
-
c#菜单动态合并的实现方法
-
用 Vue.js 递归组件实现可折叠的树形菜单(demo)
-
C#实现Winform动态添加菜单的方法
-
c#菜单动态合并的实现方法
-
用 Vue.js 递归组件实现可折叠的树形菜单(demo)
-
C#实现Winform动态添加菜单的方法