views:

851

answers:

4

Whats is the best method to create nested checkboxlists in ASP.net?

Should I be using a datagrid? Should I be using a treeview with checkboxes enabled?

I have the data I need in a datatable, and would like to loop through through it to create a checkboxlist with a nested chechboxlist for each parent checkbox.

Cheers!

A: 

I would use a Treeview for this, but the ASP.NET 2.0 Treeview control doesn't have templated nodes. If you want to use a Treeview it would have to be a third-party control that supports templates.

You could also "roll your own" user control (or composite control if you're feeling ambitious) with CSS positioning or tables. More work, but free.

Dave Swersky
A: 

It really depends on your data requirements, your database schema and the UI technology.

For web sites I've had a lot of success with nested UL/LI tags created from hierarchical "paths"; this allows me to hide/check/etc all checkboxes under a parent by finding the child list.

I use the "path" technique from Itzak Ben-Gan; he has lots of MS SQL Server-related stuff on his site at www.sql.co.il and also has an article "Maintaining Hierarchies" on www.sqlmag.com, with downloadable code.

HTH.

devstuff
+1  A: 

The Telerik RadAjax control suite has a tree view that can do this

treeview checkbox support demo

You can bind to a hierarchical data source or to an xml document, create your own templates, etc.

Nick
+1  A: 

I've never been a fan of grids, instead, I use repeaters/listviews and for each row I have a UserControl that is responsible for showing the row data, and further repeaters for sub-data.

Tiny example:

<asp:repeater id... runat...>
    <itemtemplate>
        <uc1:MyRowControl id... runat... OnSomeEvent='MyRowHandler' Model='<%# (MySubData)Container.DataItem %>'
    </itemtemplate>
</asp:repeater>

and so on internally. Events is easy to handle when you do like this.

Tommy