当前位置:网站首页>ASP. Net read database bound to treeview recursive mode
ASP. Net read database bound to treeview recursive mode
2022-07-28 06:20:00 【Haile learning】

Create tables and insert analog data :
CREATE TABLE [sysMenuTree](
[NoteId] [decimal](18, 0) NOT NULL,
[ParentId] [decimal](18, 0) NULL,
[sText] [nvarchar](50) NULL,
[sValue] [nvarchar](50) NULL,
[sURL] [nvarchar](50) NULL,
[sTarget] [nvarchar](50) NULL,
[Chger] [nvarchar](50) NULL,
[ChgTime] [nvarchar](50) NULL)
insert into sysMenuTree values(3,0,N' Catalog ',N' Catalog ','','','','')
insert into sysMenuTree values(4,0,N' Catalog ',N' Catalog ','','','','')
insert into sysMenuTree values(5,0,N' Catalog ',N' Catalog ','','','','')
insert into sysMenuTree values(6,3,N' Project .1',N' Project .1','','','','')
insert into sysMenuTree values(7,3,N' Project .2',N' Project .2','','','','')
insert into sysMenuTree values(8,4,N' Project .1',N' Project .1','','','','')
insert into sysMenuTree values(9,4,N' Project .2',N' Project .2','','','','')
insert into sysMenuTree values(10,4,N' Project .3',N' Project .3','','','','')
insert into sysMenuTree values(11,5,N' Project .1',N' Project .1','','','','')
insert into sysMenuTree values(12,5,N' Project .2',N' Project .2','','','','')stay ASP.NET Read data bound to TreeView Implementation code :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="treeMenu" runat="server">
</asp:TreeView>
</div>
</form>
</body>
</html>using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
private readonly string ConnString = @"server=.\MSSQLSERVER2008;database=chart;uid=sa;pwd=123456";
private DataTable dt = null;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
dt = new DataTable();
GetMenuToDataTable("select * from sysMenuTree",dt);
BindTree(dt,null,"0");
}
}
private void BindTree(DataTable dtSource,TreeNode parentNode,string parentID)
{
DataRow[] rows = dtSource.Select(string.Format("ParentID={0}",parentID));
foreach(DataRow row in rows)
{
TreeNode node = new TreeNode();
node.Text = row["sText"].ToString();
node.Value = row["sValue"].ToString();
BindTree(dtSource,node,row["NoteId"].ToString());
if(parentNode == null)
{
treeMenu.Nodes.Add(node);
}
else
{
parentNode.ChildNodes.Add(node);
}
}
}
private DataTable GetMenuToDataTable(string query,DataTable dt)
{
using(SqlConnection conn = new SqlConnection(ConnString))
{
SqlCommand cmd = new SqlCommand(query,conn);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.Fill(dt);
}
return dt;
}
}边栏推荐
- (PHP graduation project) based on PHP student daily behavior management system access
- 4、 Model optimizer and inference engine
- Deep learning (II) into machine learning and deep learning programming
- Interpreting the knowledge in a neural network
- EIGamal cryptosystem description
- 浪涌冲击抗扰度实验(SURGE)-EMC系列 硬件设计笔记6
- Tensorflow2.1 basic concepts and common functions
- 三极管设计,理解饱和,线性区域和截止区
- Research on threat analysis and defense methods of deep learning data theft attack in data sandbox mode
- Summary of command injection bypass methods
猜你喜欢

(PHP graduation project) based on PHP student daily behavior management system access

ESXi on Arm 10/22 更新

PLC的选型

Nanjing University of Posts and Telecommunications CTF topic writeup (I) including topic address

Notes on the thinking of software analysis and library acquisition of a Taobao customer

(PHP graduation project) obtained based on PHP novel website management system

论福禄克DTX-1800如何测试CAT7网线?

浅谈FLUKE光缆认证?何为CFP?何为OFP?

一个票据打印实例

Building neural network based on tensorflow
随机推荐
TVS管参数与选型
五、视频处理与GStreamer
Transformer's understanding
PLC的整体认识
Transformer 自注意力机制 及完整代码实现
CalendarExtender控件的中文显示问题
Overview of unconstrained low resolution face recognition III: homogeneous low resolution face recognition methods
Agilent Agilent e5071 test impedance and attenuation are normal, except crosstalk ng--- Repair plan
将GrilView中的数据转换成DataTable
Tornado first met
(PHP graduation project) obtained based on PHP novel website management system
Model Inversion Attacks that Exploit Confidence Informati on and Basic Countermeasures 阅读心得
Tensorflow2.1 basic concepts and common functions
光伏发电系统——mppt最大功率点追踪
深度学习(一):走进机器学习与深度学习理论部分
(PHP graduation project) based on PHP Gansu tourism website management system to obtain
怎么看SIMULINK直接搭的模块的传递函数
Photovoltaic power generation system MPPT maximum power point tracking
Interpreting the knowledge in a neural network
frameset 用法示例