Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sherry Ann Hernandez 320 posts 344 karma points
    Jan 27, 2011 @ 12:47
    Sherry Ann Hernandez
    0

    How do I loop through the contents of embedded content

    Hello,

    How can I loop through the items inside the embedded content?

  • Sascha Wolter 615 posts 1101 karma points
    Jan 27, 2011 @ 13:06
    Sascha Wolter
    0

    Hi Sherry,

    the easiest way is probably by using XSLT, I have attached a simple example on the project page (look under screenshots). E.g. if your Embedded Content control has the alias 'productSpecifications', is located on the current page and has 2 properties with alias 'name' and 'value', you could do something like this:

    <ul>

    <xsl:for-each select="$currentPage/productSpecifications[@isDoc]/data/item">

      <li>

        <xsl:value-of select="./name">: <xsl;value-of select="./value">

      </li>

    </xsl:for-each>

    </ul>

    Hope that makes sense. I'll upload a new, pretty much reworked version of the datatype in a bit, the frontend stays the same but the backend has had a good revamp due to some issues that have come up. IE made my life quite hard here, but it seems like I'll have the upper hand for now.

    Cheers, Sascha

  • Patrick McAndrew 48 posts 163 karma points
    Mar 07, 2011 @ 13:30
    Patrick McAndrew
    1

    For those of you looking for a .net usercontrol sample using a repeater:

     

    protected void Page_Load(object sender, EventArgs e)
    {
    /* some code here to get the node you want */

            string productSpecifications = node.GetProperty(productSpecifications).Value;

            if (!string.IsNullOrEmpty(productSpecifications))
            {
                    XmlDataSource ds = new XmlDataSource();
                    ds.Data = productSpecifications;
                    ds.EnableCaching = false;

                    Repeater1.DataSource = ds;
                    Repeater1.DataBind();
            }
    }

     

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
         if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    {
             var name = XPathBinder.Eval(e.Item.DataItem, "./name");
             var value = XPathBinder.Eval(e.Item.DataItem, "./value");
    }
    }

     

  • Michael Falch Madsen 70 posts 92 karma points
    May 16, 2011 @ 14:42
    Michael Falch Madsen
    0

    Anyway to do that without a repeater?

  • Patrick McAndrew 48 posts 163 karma points
    May 17, 2011 @ 08:31
    Patrick McAndrew
    0

    You should be able to use a GridView as well - just set the gridview datasource & then databind it.  Or did you mean using something else?

     

  • Michael Falch Madsen 70 posts 92 karma points
    May 17, 2011 @ 08:48
    Michael Falch Madsen
    0

    I would like to make a simple for-loop like in xslt..

     

    Tried your example but could'nt get my value out.

     

    string surveyAnswers = node.GetProperty("surveyAnswers").Value;

                if (!string.IsNullOrEmpty(surveyAnswers))
                {
                    XmlDataSource ds = new XmlDataSource();
                    ds.Data = surveyAnswers;
                    ds.EnableCaching = false;

                    Repeater Repeater1 = new Repeater();

                    Repeater1.DataSource = ds;
                    Repeater1.DataBind();               

                    foreach (RepeaterItem item in Repeater1.Items)
                    {                   
                        var name = XPathBinder.Eval(item.DataItem, "./name");
                        var value = XPathBinder.Eval(item.DataItem, "./value");

                        lit.Text += name + " :: " + value + "<br />";
                    }

                    // Test!
                    lit.Text += "all answers " + node.GetProperty("surveyAnswers").Value + "\n\n";
                }

  • Patrick McAndrew 48 posts 163 karma points
    May 17, 2011 @ 10:36
    Patrick McAndrew
    0

    Did you hook up your repeater to the ItemDataBound event in the source code (not codebehind)? 

     

    Based on your example, I would try something like (untested code, so make adjustments as required):

    string surveyAnswers = node.GetProperty("surveyAnswers").Value;
                if (!string.IsNullOrEmpty(surveyAnswers))
                {
          XmlDataSource ds = new XmlDataSource();
                    ds.Data = surveyAnswers;
                    ds.EnableCaching = false;
                   DataView dv = ds.Select(DataSourceSelectArguments.Empty) as DataView;
                   DataTable dt = dv.ToTable();

                foreach(var row in dt.Rows)
    {
    // do something
    }
    }

     

  • Michael Falch Madsen 70 posts 92 karma points
    May 23, 2011 @ 09:55
    Michael Falch Madsen
    0

    I'm building all dynamic in codebehind so can't add a controls in design view. ended up using child nodes which works fine- but i don't like having nodes in my tree which are not pages

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies