Solved

asp:repeater - menu - submenu

Posted on 2013-01-21
3
2,068 Views
Last Modified: 2013-01-24
Hello,
I would like to create a menu with submenuitems like this using asp:Repeater.
<ul>
			<li id="li1" runat="server">Menu 1
				<ul>
					<li>Submenu1</li>
					<li>Submenu2</li>
				</ul>
			</li>
			<li id="li2" runat="server">Menu 2</li>
		</ul>

Open in new window


Here below you see what I have done so far. This creates a normal menu. I do not know how to add the submenu. I appreciate your help

<asp:Repeater ID="rptTest" runat="server">
			<HeaderTemplate>
				<ul>
			</HeaderTemplate>
			<ItemTemplate>
				<%#Eval("FullName") %><li>Value
				</li>
			</ItemTemplate>
			<FooterTemplate>
				</ul>
			</FooterTemplate>
		</asp:Repeater>

Open in new window


In code behind I bind to it like this

protected void Page_Load(object sender, EventArgs e)
    {
		List<User> iList = new List<User>();
		User i = new User();
		i.FullName = "MenuItem1";
		iList.Add(i);
		User i2 = new User();
		i2.FullName = "MenuItem2";
		iList.Add(i2);
		rptTest.DataSource = iList;
		rptTest.DataBind();
    }

Open in new window

0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38802033
Try this,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="repeaterULFil.aspx.cs" Inherits="repeaterULFil" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:Repeater ID="rptTest" runat="server" OnItemDataBound="rptTest_ItemDataBound">
        <HeaderTemplate>
            <ul>
        </HeaderTemplate>
        <ItemTemplate>
            <li>
                <%#Eval("FullName") %>
                <asp:Repeater ID="rptTest1" runat="server" >
                    <HeaderTemplate>
                        <ul>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <li>
                            <%#Eval("FullName") %></li>
                    </ItemTemplate>
                    <FooterTemplate>
                        </ul>
                    </FooterTemplate>
                </asp:Repeater>
            </li>
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
    </form>
</body>
</html>

Open in new window

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class repeaterULFil : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        rptTest.DataSource = ds();
        rptTest.DataBind();

       
    }

    protected void rptTest_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptrSubSubCategory = (Repeater)e.Item.FindControl("rptTest1");
            rptrSubSubCategory.DataSource = ds();
            rptrSubSubCategory.DataBind();
        }
    }
     List<User> ds()
    {
        List<User> iList = new List<User>();
        User i = new User();
        i.FullName = "MenuItem1";
        iList.Add(i);
        User i2 = new User();
        i2.FullName = "MenuItem2";
        iList.Add(i2);
        User i3 = new User();
        i3.FullName = "MenuItem3";
        iList.Add(i3);
        User i4 = new User();
        i4.FullName = "MenuItem4";
        iList.Add(i4);
        return iList;
    }
    class User {
        private string myName;
        public string FullName
        {
            get
            {
                return myName;
            }
            set
            {
                myName = value;
            }
        }

    }
}

Open in new window

0
 

Author Comment

by:johnkainn
ID: 38802186
Thank you. Some items will have sub menus but others not. Is it possible that you send a demo how I would get following output

Menu1
     Submenu1
     Submenu2
Menu 2 (no submenu)

or like this:

<ul>
                  <li id="li1" runat="server">Menu 1
                        <ul>
                              <li>Submenu1</li>
                              <li>Submenu2</li>
                        </ul>
                  </li>
                  <li id="li2" runat="server">Menu 2</li>
            </ul>
0
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 500 total points
ID: 38803984
yes, possible, i hope the child repeater is based on parent repearer key. On itemdatabound event you can configure .
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question