Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Sep 10, 2010 @ 15:31
    Phil Crowe
    0

    Repeater not listing last node in list

    I have a repeater i want to use to list every node name within a hidden field. i want to then extract that value in the code behind during databound. For some reason that last node in the list will not appear.

    <asp:Repeater ID="rptStockists" runat="server" OnItemDataBound="rowRepeater_ItemBound">

    <ItemTemplate>

    <asp:HiddenField ID="HdName" runat="server" Value='<%#((Node)Container.DataItem).Name%>' />

    </ItemTemplate>

    </asp:Repeater>

            public void DisplayAll()

            {

                Response.Write("items before being repeated: ");

                foreach (Node child in n.Children)

                {

                    nodes.Add(child);

                    Response.Write(child.Name);

                }

                Response.Write(" |  Items after repeated: ");

                rptStockists.DataSource = nodes;

                rptStockists.DataBind();

     

            }

            protected void rowRepeater_ItemBound(object sender, RepeaterItemEventArgs e)

            {  

                foreach (RepeaterItem item in rptStockists.Items)

                {

    HiddenField hiddenName = (HiddenField)item.FindControl("HdName");

                    Response.Write(hiddenName.Value+",");

       }

         }

     

    items before being repeated: shop1shop2shop3shop4shop5 shop6shop7shop8shop9shop10shop11 | Items after repeated: shop1,shop1,shop2,shop1,shop2,shop3,shop1,shop2,shop3,shop4,shop1,shop2,shop3,shop4,shop5,shop1,shop2,shop3,shop4,shop5, shop6,shop1,shop2,shop3,shop4,shop5, shop6,shop7,shop1,shop2,shop3,shop4,shop5, shop6,shop7,shop8,shop1,shop2,shop3,shop4,shop5, shop6,shop7,shop8,shop9,shop1,shop2,shop3,shop4,shop5, shop6,shop7,shop8,shop9,shop10,

     

    As you can see shop 11 does not show after the data has been bound.

     

    Any ideas? its like the a limit on how many items i can have in the repeater. Ive tried moving shop11 higher up but this just meant shop 10 disappeared. 

     

     

     

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Sep 10, 2010 @ 16:18
    Michael Latouche
    0

    Hi Phil,

    Do you actually need to get the value at each item binding? Otherwize you could catch the global "Bound" event of the repeater at the end, and get everything at once.

    My guess is that in the Item_Bound method, the item has been bound, but not added to the repeater itedm list yet. This would mean that in fact, the first time you get into the event, there is nothing in the list. So, your first entry "shop1", would actually be displayed in the second loop, etc.

    This is just a guess since I can't make any test for the moment, but you could easily find out if it is the case by displaying some text before entering your loop. That way you can see if the first time you get some text out of the loop or not.

    So, for example:

            protected void rowRepeater_ItemBound(object sender, RepeaterItemEventArgs e)
            {  
                Response.Write("In ItemBound: " + rptStockists.Items.Count); 
                foreach (RepeaterItem item in rptStockists.Items)
                {
                     HiddenField hiddenName = (HiddenField)item.FindControl("HdName");
                     Response.Write(hiddenName.Value+",");
                }
             }

    Hope this helps.

    Cheers,

    Michael

  • Phil Crowe 192 posts 256 karma points
    Sep 10, 2010 @ 17:01
    Phil Crowe
    0

    Thanks mike. The response.write before entering the loop confirmed that store10 was the last in the loop. I dont get what has happened to the store11. 

  • Phil Crowe 192 posts 256 karma points
    Sep 17, 2010 @ 16:02
    Phil Crowe
    0

    I never really solved this one. i just created a dud node that was last in the list. Seeing as the last node never gets read it meant that store11 now shows.

Please Sign in or register to post replies

Write your reply to:

Draft