nested bulletedlist ?

  • Thread starter Thread starter craptiger
  • Start date Start date
C

craptiger

Is it possible to nest bulleted lists? I'm not overly competent at c#
yet but have been given a project by my boss and it involves making a
menu type control from a 3 level xml file.
I've managed to build it by making one list, and dynamically adding
items to it, but want to indent them by nesting lists within lists.
Can anyone post a really simple example of how I might do this?
 
As it often turns out, it would have been easier trying it rather than
posting to a C# newsgroup and waiting for an answer.
Short answer: yes.
Example:
<ul>
<li>line 1
<li> line 2
<div>
<ul>
<li> indented sublist
</ul>
</div>
</ul>
 
My apologies, I should have explained a little further.
I'm trying to create it like this...

BulletedList mybList = new BulletedList();
ListItem li = new ListItem();
li.Value = "myvalue";
li.Text = "mytext";
myList.Items.Add(li);

However I can't add another BulletedList control to a ListItem, or to
another BulletedList.

BulletedList subList = new BulletedList();
myList.Controls.Add(subList);

I don't think I'm just being lazy, I know the principle of hard coding
lists in html as you showed me, but it must be possible to do this
dynamically?

Thanks,
 
Sure, you could do it dynamically.
Each HTML element you need can be created as an HtmlGenericControl, and you
can nest them accordingly, then attach the main one either to either a
Placeholder or say, a Panel.
If you are adventurous, you could even build a custom control to do the same.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
Perfect- thank you. It does seem strange though, that I have to use
the generic control when there's this wonderful bulletedlist control.
Maybe it's just me but I would have thought it would have been sensible
to allow adding sub lists.
Anyway, thanks again.

B
 
Hi,

Just realised another stumbling block...

My nice BulletedList control had an auto postback, and was telling me
on postback which one had been clicked. How can I make this control
postback when a link in the menu is clicked?
I can't get it to runat server.
I think I might be going about this whole thing the wrong way here!!!

Any ideas?
 
got around it by dynamically adding linkbuttons, which post back.
not ideal but it works!

Thanks for your help anyway.

B
 
Back
Top