将数据从数据库加载到Treeview C# [英] load data from data base to treeview C#

查看:126
本文介绍了将数据从数据库加载到Treeview C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#语言将数据库中1个表中的数据加载到树形视图中,

并且此表在其中的2列之间具有递归关系...

I want to load data from 1 table in my database to a tree view using C# language ,,

and this table has a recursive relation between 2 columns in it...

推荐答案

Letz假定两个列名称分别为col1和col2.代码示例PageLoad()是:

Letz assume two column names are col1 and col2. Code sample PageLoad() is:

foreach (DataRow row in myTable.Rows)
{
    TreeNode node = new TreeNode(dr["col1"], dr["col2"]);
    node.PopulateOnDemand = true;

     TreeView1.Nodes.Add(node);
 }
 ///
 protected void PopulateNode(Object sender, TreeNodeEventArgs e)
 {
     string col1Id = e.Node.Value;
     foreach (DataRow row in myTable.Rows)
     {
         TreeNode node = new TreeNode(dr["col1"], dr["col2"]);
         node.PopulateOnDemand = true;

         e.Node.ChildNodes.Add(node);
     }

 }


这篇关于将数据从数据库加载到Treeview C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆