asp.net 之 数据库导入treeview

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DBHelper; public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sqlstr = "select item_id,item_name,parent_id from para_item"; } protected void addtree(int Pid, TreeNode Pnode)
{
string sqlstr = "select item_id,item_name,parent_id from para_item";
DataTable dt =SqlHelper.GetTableText(sqlstr, null)[0]; if (dt.Rows.Count > 0)
{
DataView dv = new DataView(dt);
dv.RowFilter = "[Parent_ID]=" + Pid;
foreach (DataRowView Row in dv)
{
//声明节点
TreeNode node = new TreeNode();
//绑定超级连接
node.NavigateUrl = string.Format("javascript:show('{0}')", Row["item_name"].ToString()); if (Pnode == null)
{
node.Text = Row["item_name"].ToString();
TreeView1.Nodes.Add(node);
node.Expanded = true; //节点状态
addtree(Int32.Parse(Row["Parent_ID"].ToString()), node); }
else {
node.Text = Row["item_name"].ToString();
Pnode.ChildNodes.Add(node);
node.Expanded = true; //节点状态
addtree(Int32.Parse(Row["Parent_ID"].ToString()), node); } }
}
}
}

  

上一篇:Java-Vector


下一篇:vscode运行前端代码