repeater in repeater

In a web site in ASP.NET 2.0 with C# I have a repeater inside a repeater that is bound to xm file.
In the inner repeater in the DataSource what do I write?
(something with container.dataitem but was is the casting?
Anat
ANAT2403Asked:
Who is Participating?
 
McExpCommented:
You've not included your XmlDataSource, Have you set an XPath statement in your XmlDataSource?
Your XPathSelect should be a sub select from the repeater node and not from the Xml Root.

See Below for the solution to your question (I've formated it as a bulleted list).

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" XPath="/Everything/Category" />
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>
    <FooterTemplate>
        </ul></FooterTemplate>
    <ItemTemplate>
        <li>
            <%#XPath("title")%>
        </li>
        <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# XPathSelect("SubCategory") %>'>
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <FooterTemplate>
                </ul></FooterTemplate>
            <ItemTemplate>
                <li>
                    <%#XPath("title") %>
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>
0
 
McExpCommented:
I belive it would depend on the objects in the parent datasource and the objects to which you intend to itterate over.
0
 
ANAT2403Author Commented:
If I have a sitemap file so I write:
 <asp:Repeater runat="server" ID="LeftsubMenusub"     DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
but if it a regulare xml file what do I write instead sitemapnode and childnodes?
This is the xml file:
<?xml version="1.0" encoding="utf-8" ?>
<Everything>
      <Category name="Cameras">
            <title>Cameras</title>
            <Url>"~/default.aspx?p=51"</Url>
            <SubCategory name="Digital Cameras">
                  <title>Digital Cameras</title>
                  <Url>"~/default.aspx?p=1"</Url>
            </SubCategory>
            <SubCategory name="Film Cameras">
                  <title>Film Cameras</title>
                  <Url>"~/default.aspx?p=2"</Url>
            </SubCategory>

      </Category>
      <Category name="Clothing">
            <title>Clothing</title>
            <Url>"~/default.aspx?p=52"</Url>
            <SubCategory name="Clothing">
                  <title>Clothing</title>
                  <Url>"~/default.aspx?p=11"</Url>
            </SubCategory>
            <SubCategory name="Shoes">
                  <title>Shoes</title>
                  <Url>"~/default.aspx?p=12"</Url>
            </SubCategory>

      </Category>
</Everything>

Thankyou
anat
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
McExpCommented:

try
((XmlNode) Container.DataItem).ChildNodes
0
 
McExpCommented:
Are you aware of the XPath and XPathSelect Commands?

http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/092706-1.aspx
0
 
ANAT2403Author Commented:
Hi McExp.
It is not working for me.
If I write the following:
----------------------------
       <asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
            <ItemTemplate>
       
                <%#XPath("title")%><br />
                           
       
                 <asp:Repeater  ID="Repeater2" runat="server"    DataSource='<%#((System.Xml.XmlNode)Container.DataItem).ChildNodes %>'>
                    <ItemTemplate>
                    <br />
                    <%#XPath("title") %><br />
                     </ItemTemplate>
                </asp:Repeater>                    
       
        </ItemTemplate>


I get an error :     Unable to cast object of type 'System.Web.UI.WebControls.XmlDataSourceNodeDescriptor' to type 'System.Xml.XmlNode'

If I write the following:
---------------------------
       <asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
            <ItemTemplate>
       
                <%#XPath("title")%><br />
                           
       
                 <asp:Repeater  ID="Repeater2" runat="server"    DataSource='<%#XPathSelect("/Everything/Category/SubCategory") %>'>
                    <ItemTemplate>
                    <br />
                    <%#XPath("title") %><br />
                     </ItemTemplate>
                </asp:Repeater>                    
       
        </ItemTemplate>
        </asp:Repeater>

I get the first node and then second node of first node and second node of second node, then second node and second node of first node and second node of second node. the seconds node appear twice.
What should I do?
0
 
ANAT2403Author Commented:
Very Very good.
Thankyou very much.
I guess we have different hours. when I work you sleep and when you work I sleep.
Anat
0
 
ANAT2403Author Commented:
Hi McExp,
I have a small question for you if you don't mind:
You remember you answered me in another question that for sitemap if I want to show something in a repeater inside a repeater according to a condition I write:
 <span id="MenuSep"  runat="server" visible='<%# (((SiteMapNode)Container.DataItem).NextSibling!=null)
If now I have an XML file instead of the sitemap i n the format you gave me how do I enter a sentece like this after the second  <%#XPath("title") %>
Thankyou
Anat
0
 
McExpCommented:
<%# ((System.Xml.XmlLinkedNode)Container.DataItem).NextSibling != null %>
0
 
ANAT2403Author Commented:
Hi McExp,
Again thankyou very much.
It works perfect.
Anat
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.