回到今天的主题,使用TreeView控件可以很方便地实现无限级的树状结构管理。适用于无限级商品分类(类别)管理、员工类型管理、地区划分等应用场合。

  费话少说,我们就开始实现吧!

第一步,设计数据库表。
  为了实现无限级的树状层次结构,我们可以设计下边表结构。
使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件
  其中,SortId为分类的ID;ParentSortId为上下文分类的父类Id,如果是各不相干的老祖宗(不同系列的根),其父类Id可设为空;Descr为文本文明,将显示在页面上;ImageUrl是每个树结点的文本的前置图标的图片Url,此内容是与控件的ImagesBaseUrl属性相关的,也就是说会从ImagesBaseUrl 属性指定的URL开始找这里的图片。

  测试数据如下:
使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件

第二步,把新建工程并把一个TreeView控件和一个按钮及两个Label拖到WebForm上。如图:
使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件

第三步,设置TreeView属性
控件的属性太多不能一一介绍,其实很多属性从名称上已经能猜到是用来干嘛的了,嘿~具体每个属性的说明请查看文档,这里就贴上前台代码以供参考。
 1
其中<ComponentArt:TreeView>标签的属性可以从VS的属性编辑区找到相应的项。

第四步,编写后台代码
这个嘛,不费话太多了,代码说明一切吧!(已包括事件处理)
  1使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件//=======================================
  2使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件// 数据驱动的TreeView演示
  3使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件//=======================================
  4使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件// by Ryu666 in 2005/12/15  QQ:126940
  5使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件//=======================================
  6使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System;
  7使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Collections;
  8使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.ComponentModel;
  9使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Data;
 10使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Drawing;
 11使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Web;
 12使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Web.SessionState;
 13使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Web.UI;
 14使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Web.UI.WebControls;
 15使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using System.Web.UI.HtmlControls;
 16使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件
 17使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using Microsoft.Practices.EnterpriseLibrary.Data;
 18使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件using ComponentArt.Web.UI;
 19使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件
 20

效果图:
使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件

  最后就是要提示一下,这套第三方控件的其它好些控件都有类似的“动态生成”支持,它们的工作原理也都大致相同的,概括地说就是把数据从数据库或者XML文档里面读出来,装载到DataSet里面,然后通过相应的方法将DataSet里面的数据“绑定”到控件中。另外就是提供学习这套控件的两个法宝——“Samples”和“文档”,它们可以帮助你迅速地把这套控件玩透。

相关文章:

  • 2021-06-04
  • 2021-06-20
  • 2022-12-23
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
相关资源
相似解决方案