Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

repeater in repeater

Posted on 2007-10-14
10
Medium Priority
?
1,122 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:ANAT2403
  • 5
  • 5
10 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20074046
I belive it would depend on the objects in the parent datasource and the objects to which you intend to itterate over.
0
 

Author Comment

by:ANAT2403
ID: 20074071
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
 
LVL 16

Expert Comment

by:McExp
ID: 20074082

try
((XmlNode) Container.DataItem).ChildNodes
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Expert Comment

by:McExp
ID: 20074092
Are you aware of the XPath and XPathSelect Commands?

http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/092706-1.aspx
0
 

Author Comment

by:ANAT2403
ID: 20076794
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
 
LVL 16

Accepted Solution

by:
McExp earned 2000 total points
ID: 20081390
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
 

Author Comment

by:ANAT2403
ID: 20081718
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
 

Author Comment

by:ANAT2403
ID: 20083978
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
 
LVL 16

Expert Comment

by:McExp
ID: 20087574
<%# ((System.Xml.XmlLinkedNode)Container.DataItem).NextSibling != null %>
0
 

Author Comment

by:ANAT2403
ID: 20091471
Hi McExp,
Again thankyou very much.
It works perfect.
Anat
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 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