Bind DropDownList with Hierarchy from MSSQL Table with ASP.NET C#

Posted by Gal V on Stack Overflow See other posts from Stack Overflow or by Gal V
Published on 2010-04-27T13:11:58Z Indexed on 2010/04/27 13:13 UTC
Read the original article Hit count: 869

Filed under:
|
|
|
|

Hello all,
I have the following sql table which contains menu (website menu) data.

Table Name: MenuItems
Columns: Id, MenuId, ParentMenuItemId, Text.

My goal is to bind a DDL according to the following hierarchy (example):

Id: 1, MenuId: 1, ParentMenuItemId: -1, Text: 'One'
Id: 2, MenuId: 1, ParentMenuItemId: 1, Text: 'Two'
Id: 3, MenuId: 1, ParentMenuItemId: 1, Text: 'Three'
Id: 4, MenuId: 1, ParentMenuItemId: 2, Text: 'Four'
Id: 5, MenuId: 1, ParentMenuItemId: 4, Text: 'Five'

Requested result in DDL:

One
-- Two
---- Four
------ Five
-- Three

I think it should contain 'WITH' SQL command.
Thanks all!

© Stack Overflow or respective owner

Related posts about binding

Related posts about dropdownlist