Monday, October 29, 2007

How to make a TreeView Control in ASP.Net 1.1 and populate it from the database.

As Treeview control is not a control in ASP.Net1.1 so we have to use a third party control, to compensate for that.
The following article will help you in that:-
Downloaded Web-Controls from one of links below:

1)http://msdn.microsoft.com/library/default.asp?url=/workshop/webcontrols/behaviors/library/treeview/treeview.asp
2)http://msdn.microsoft.com/archive/en-us/samples/internet/asp_dot_net_servercontrols/webcontrols/(This has the installable).

a)After running the installable, we get a folder named IE Web Controls in
C:\Program Files.
b)Then execute the Build.bat file ( A folder named Build will be created).
c)Copy the dll to your Project Bin Folder.
d)Since we have already copied the Web Control(dll) to our Project Folder(BIN)
e)In the Solution Explorer(.net) add a new Reference, a Dialog Box will open.
Browse to the Microsoft.Web.UI.WebControls (which is residing in the BIN folder
of your current project)by clicking the Browse Button.
f)Now create a folder named webctrl_client under c:\inetpub\wwwroot and under
webctrl_client create a folder named 1_0.
g)In the folder 1_0 copy the content of the Runtime under C:\Program Files\IE Web
Controls\build.

Now you are ready to use the Treeview control in your Project.
Add the following namespaces in your webpage where you shall be using the treeview control:
import namespace="Microsoft.Web.UI.WebControls"
Register TagPrefix="Treeview1" Namespace="Microsoft.Web.UI.WebControls"
Assembly="Microsoft.Web.UI.WebControls"

Add the following tag in the HTML part:
VIEW1:TREEVIEW id=Treeview1 runat="server" Width="194px" Height="185px" BackColor="LavenderBlush" BorderStyle="Ridge" AutoPostBack="True" ExpandLevel="1" Enableviewstate="true" onselectedindexchange="cal" NAME="Treeview1">Populating the Treeview Control from the database:
Write the following in Public Fuction Cal()
Create a new node for the tree-
Dim node as TreeNode()
chan_desc=DS1.Tables("Channel").Rows(i).item("channel_desc")
chan_id=DS1.Tables("Channel").Rows(i).item("channel_id")
node.Text=chan_desc
node.Id=chan_id
noder.Nodes.Add(node)

Repeat the above steps to add as many nodes you want.
The next node will be added by-
node.Nodes.Add(node1)

That is it, now you are ready to incorporate Treeview Control in ASP.Net 1.1.

2 comments:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Impressora e Multifuncional, I hope you enjoy. The address is http://impressora-multifuncional.blogspot.com. A hug.

Anonymous said...

This is great info to know.