The web interface is becoming more advanced...In this article Himanshu shows us a simple example of how to use the TreeView and TabStrip IE Web Controls with VB.NET.
So here a TreeView is created on your page and we will use "tvgroups" to refer it later.
Now the code behind page (Treeview.aspx.vb):
Imports Microsoft.Web.UI.WebControls Imports System.Data.SqlClient Public Class Treeview Inherits System.Web.UI.Page Protected WithEvents tvGroups As Microsoft.Web.UI.WebControls.TreeView Dim connString = "your connection string for database" Dim myConnection As New SqlConnection(connString) Dim dtid, dtname As String
Here I am building the tree view with the values from the database, so now the remaining code is working with DataSets, DataRows and DataTables. If you know how to use them it’ll be easy for you, if not then there’s plenty of documentation about how to use them.
The following code goes in the Page_Load event/method:
If Not Page.IsPostBack Then Dim mysqladapter As New SqlDataAdapter() Dim mydataset As New DataSet() Dim pNode, pChild As TreeNode Dim dttable As DataTable Dim dtrow As DataRow Dim countrow As Integer Dim dtcolumn As DataColumn mysqladapter = New SqlDataAdapter("Fetch_departments", myConnection) mysqladapter.Fill(mydataset, "tbl_no_sales_days") Dim myDataView As DataView = New DataView(mydataset.Tables("tbl_no_sales_days")) myDataView.Sort = "departmentregionid" countrow = myDataView.Count pNode = New TreeNode() pNode.Text = "ALL DEPARTMENTS" pNode.NavigateUrl = "" tvGroups.Nodes.Add(pNode) For Each dttable In mydataset.Tables For Each dtrow In dttable.Rows dtid = dtrow(0) dtname = dtrow(1) pChild = New TreeNode() pChild.NavigateUrl = "http://www.oxx.no" pChild.Text = dtname pChild.ID = dtid pNode.Nodes.Add(pChild) Next Next End If
In the code above "Fetch_departments" is a stored procedure which returns regions and departments.