Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2007, 02:53 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help me with repeater control?

Anyone can help me. The following is problem.
I want create a navigation menu depend on file XML datasource?

I want use Nested Repeater and XML Data create a menu as:
[list]

<li>AAAA</li>[list]
<li>aaa</li>
<li>aaa</li>[list]
<li>BBBB</li>[list]
<li>bbbb</li>
</ul>
</ul>

<?xml version="1.0" encoding="utf-8" ?>
<Data>
    <MenuItem>
        <ID>1</ID>
        <ParentID>0</ParentID>
        <Icon></Icon>
        <Text>AA</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>2</ID>
        <ParentID>1</ParentID>
        <Icon></Icon>
        <Text>aaa</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>3</ID>
        <ParentID>1</ParentID>
        <Icon></Icon>
        <Text>aaaaa</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>4</ID>
        <ParentID>1</ParentID>
        <Icon></Icon>
        <Text>aaaa</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>5</ID>
        <ParentID>1</ParentID>
        <Icon></Icon>
        <Text>aaaaa</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>6</ID>
        <ParentID>0</ParentID>
        <Icon></Icon>
        <Text>BBBBB</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>7</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>8</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>9</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbbbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>10</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>11</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>12</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>13</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>14</ID>
        <ParentID>6</ParentID>
        <Icon></Icon>
        <Text>bbb</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftChildMenuItem</CssClass>
    </MenuItem>
    <MenuItem>
        <ID>15</ID>
        <ParentID>0</ParentID>
        <Icon></Icon>
        <Text>CCCCC</Text>
        <NavigatiorUrl></NavigatiorUrl>
        <CssClass>MLeftMenuItem</CssClass>
    </MenuItem>
</Data>

My code:
<div id="navigation">
                [list]


                    <asp:Repeater runat="server" ID="menu" >
                        <ItemTemplate>
                            <li>
                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="....."><%# If(eval("parentID")==0) eval("Name") %></asp:HyperLink>

                                <asp:Repeater ID="Repeater1" runat="server" >
                                    <HeaderTemplate>
                                        [list]
                                    </HeaderTemplate>

                                    <ItemTemplate>
                                        <li>
                                            <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="...."><%# Eval("Name") %></asp:HyperLink>
                                        </li>
                                    </ItemTemplate>

                                    <FooterTemplate>
                                        </ul>
                                    </FooterTemplate>
                                </asp:Repeater>
                            </li>
                        </ItemTemplate>
                    </asp:Repeater>
                </ul>


            </div>

behin code:

private string xmlSource = string.Empty;

        protected void Page_Load(object sender, System.EventArgs e)
        {
            rptMenu.DataSource = GetMenu();
            rptMenu.DataBind();
        }

        private ArrayList GetMenu()
        {
            try
            {
                xmlSource = lblXmlSource.Text;
                xmlSource = Server.MapPath(xmlSource);
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlSource);

                ArrayList menu = new ArrayList();

                XmlNodeList list = doc.SelectNodes("Data/MenuItem");
                foreach (XmlNode node in list)
                {
                    try
                    {
                        int id = int.Parse(node.SelectSingleNode("ID").InnerText);
                        string name = node.SelectSingleNode("Text").InnerText;
                        int parentID = int.Parse(node.SelectSingleNode("ParentID").InnerT ext);
                        string cssClass = node.SelectSingleNode("CssClass").InnerText;
                        MenuItems item = new MenuItems(id, parentID, name, cssClass, string.Empty, true);
                        menu.Add(item);
                    }
                    catch
                    {
                        continue;
                    }
                }

                return menu;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
 
Old July 14th, 2007, 12:09 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What about using the asp:xml control with an XSL transformation?

-Peter




Similar Threads
Thread Thread Starter Forum Replies Last Post
repeater control akssmv ASP.NET 2.0 Basics 1 August 20th, 2008 08:55 PM
Repeater Control Dhanapal General .NET 0 April 2nd, 2007 04:50 AM
Repeater control. rupen ASP.NET 1.0 and 1.1 Basics 1 October 14th, 2005 08:34 AM
Repeater Control abdul_owiusa General .NET 0 August 30th, 2005 04:54 PM
Repeater Control Dmitriy Pro VB 6 0 July 27th, 2004 11:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.