Click here to Skip to main content
Click here to Skip to main content
Technical Blog

ASP.NET ListView Control

, 15 Apr 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Some time ago I needed to render hierarchical data to a / elements structure and also be able to render a special attribute to the Html elements. Using TreeView control I found no better way than re-implement the Render method, loosing the out-of-the-box binding process. Since I want to have a cont

Some time ago I needed to render hierarchical data to a <ul>/<li> elements structure and also be able to render a special attribute to the <li> Html elements.

Using TreeView control I found no better way than re-implement the Render method, loosing the out-of-the-box binding process.

Since I want to have a control similar to TreeView with all its binding richness I decide to write a ListView control.

This is the typical declaration I want to achieve:

<NG:ListView ID="orderedlistView1" runat="server" DataSourceID="SiteMapDataSource1" 
    Mode="Ordered">

  <DataBindings>

    <NG:ListNodeBinding DataMember="SiteMapNode" AttributeField="Url" TextField="Title" />

    <NG:ListNodeBinding DataMember="SiteMapNode" AttributeField="Url"
        TextField="Url" Depth="1"/>

    <NG:ListNodeBinding DataMember="SiteMapNode" AttributeField="Title"
        TextField="Title" Depth="2"/>

  </DataBindings>

</NG:ListView>

It looks pretty familiar...

In ListView control you can set the Mode property to choose whether to render an ordered list (<ol>) or an unordered list (<ul>).

Using the ListNodeBinding you can also use the AttributeField property to specify aditional attributes to rendered in the <li> html element (ex: <li Url="my Url" >some text</li>).

Also, there's no hierarchy depth limit.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Nuno M. F. Gomes
Software Developer (Senior)
Portugal Portugal
Nuno Gomes currently works as a Senior Developer for one of the major portuguese banks.
 
Gomes graduated from Instituto Superior Tecnico with a Electronics and Computers degree in 1999.
 
His daily work main focus is, since 2003, on ASP.NET. A true .NET developer with great passion for the simple solution.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 15 Apr 2010
Article Copyright 2010 by Nuno M. F. Gomes
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid