Working with Treeview webcontrol Part 1-Basics

Source: Internet
Author: User
Http://www.dnzone.com/ShowDetail.asp? Newsid= 111

One of the new gifts from. net is Internet Explorer webcontrols version 1.0 of the ASP. net server controls. this is a suite of "rich" controls that lets you easy deal with structures like Treeview, toolbar, tabcontrol and multipage that previusly needed a lot of work to be developed.

In this three-part article Oscar peli will describe one of these rich controls: Treeview. in this first part he will introduce you to the basics of this rich control. you will see your first Treeview built in a declarative mode and some others more complex samples; you will see also how to build a Treeview programmatically.

The second and third parts of this article are focused on more advanced features of this control: handling events (http://www.asptoday.com/content.asp? Id = 1858) and data binding (http://www.asptoday.com/content.asp? Id = 1859 ).

 

Introduction

TheTreeviewIs one of the most useful structures in Web development. in this first part of my article I want to introduce to you a wonderful control that Microsoft released for. net Framework. here you have a control with a rich object model that lets you program varous aspects by simply defining the value of some properties, or by declaring some elements.

Download and install webcontrols

Before reading this article it will be useful if you have downloaded and installed Microsoft Internet Explorer webcontrols version 1.0 of the ASP. NET Server controls

From the dropdown list"Webcontrols version 1.0 Installation Options"Choose"Automatic Install: webcontrols version 1.0 client DHTML behaviors and server controls".

Wait until the browser prompts you to save or execute the file (Iewebcontrols. MSI), Then save it on your hard disk and execute it.

At the end of installation, you can see in the programs menu, which can be accessed from the start button,"Microsoft Internet Explorer webcontrols"Entry. There you can find a shortcut cut to the IE webcontrols msdn documentation and a ReadMe file where you can read the step by step installer operations.

The simplest Treeview

The first sample of a Treeview is a very simple program, the source code for it can be found inFirsttree. aspxFile in the support material of this article. I won't describe everything, but I will describe the lines that are directly concerned withTreeviewControl.

The first line is@ ImportDirective for the webcontrols. This explicitly imports a namespace into the page, making all classes and interfaces of the imported namespace available. (If you want to know more on@ ImportDirective point your browser to http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconimport.asp .)

 
<% @ Import namespace = "Microsoft. Web. UI. webcontrols" %>

The second line is@ RegisterDirective that associates an alias with the namespace and class name for concise notation. Including this directive in a page allows you to layoutTreeviewServer Control Using declarativeTreeviewSyntax.

If you want to know more on@ RegisterDirective point your browser to http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconregister.asp.

 
<% @ Register tagprefix = "myfirsttree" namespace = "Microsoft. Web. UI. webcontrols" assembly = "Microsoft. Web. UI. webcontrols, version = 1.0.2.226,
Culture = neutral, publickeytoken = 31bf3856ad364e35 "%>

Note that all webcontrols elements must be authored insideFormElement.Runat = "server"Attribute has also to be specified for the form to indicate that ASP. NET will process the results of any user input. So the Treeview element is a child of the form and hasRunat = "server"Attribute too.

Note the use of the tag prefixMyfirsttree; This will be used for all the webcontrols elements in the page since it has been predefined in@ RegisterDirective.

 
<HTML>  

inside the Treeview element you can insert treenode elements to build your structure. to produce a hierarchical structure of nodes, simply add a child treenode element inside his parent element.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.