Help to create a xml menu using asp.net c#


N

nail

Hi.
I have this xml file:
<menu>
<header caption="File">
<item header="File" caption="New File"></item>
<item header="File" caption="Open File"></item>
<item header="File" caption="Close File"></item>
<item header="File" caption="New Web Site"></item>
<item header="File" caption="New Project"></item>
</header>
<header caption="Edit">
<item header="Edit" caption="Undo"></item>
<item header="Edit" caption="Redo"></item>
<item header="Edit" caption="Cut"></item>
<item header="Edit" caption="Copy"></item>
</header>
</menu>

I need to render this xml file like a menu using the followin code:
Get the headers on Page_Load()
Table tb = new Table();
TableRow tr = new TableRow();
foreach (XmlNode header in headerList)
{
TableCell tc = new TableCell();
tc.BorderWidth = Unit.Pixel(1);
tc.Attributes.Add("style", "width: 100px");
tc.Attributes.Add("columnID", tcID.ToString());
LinkButton lbt = new LinkButton();
lbt.Text = header.Attributes["caption"].Value.ToString();
lbt.Click += new EventHandler(MenuHeaderClick);
tc.Controls.Add(lbt);
tr.Cells.Add(tc);
}
tb.Rows.Add(tr);
placeholder.controls.add(tb)

And, whith the match header, I get the itens:
public MenuHeaderClick()
{
Table tb = new Table();
TableRow tr = new TableRow();
foreach (XmlNode item in itemList)
{
if (item.Attributes["header"].Value.ToString() == header)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Attributes.Add("style", "width: 100px");
tc.Attributes.Add("columnID", tcID.ToString());

LinkButton lbt = new LinkButton();
lbt.Text = item.Attributes["caption"].Value.ToString();
tc.Controls.Add(lbt);
tc.Controls.Add(new LinkButton());
tr.Cells.Add(tc);
tb.Rows.Add(tr);
}
}
placeholder.controls.add(tb)
}

The problem is, with this code my page render the menu like this:
File Edit
Undo
Redo
Cut
Copy

Well, I want the Edit menu itens above Edit, not above File, understand!
The problem is the logic to render the html table. I can't write the right
code!

Please, some body help me!

Thanks
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top