Container.ItemIndex and repeater.Items.Count

Last post 05-09-2008 7:51 PM by splitfire. 9 replies.

Sort Posts:

  • Container.ItemIndex and repeater.Items.Count

    05-07-2008, 8:10 AM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7

    I've got a repeater control that I want to do something different with the last row and the first row. The first row is easy because it is zero, so that is taken care of. However, the last row gives me some issues. I thought repeater.Items.Count would do it, but it does not seem to make when I compare the two values. I've tried using a function to fix this, but that doesn't seem to work either. For example. <%#getIndex(Container.ItemIndex)%> I've also tried using the itemBound event.

  • Re: Container.ItemIndex and repeater.Items.Count

    05-07-2008, 8:26 AM

    "what is the meaning of some thing different?" 

    using this ,repeater1.items[repeater.items.count - 1] , we can recognize the last item in repeater.

     

    but in javascript, it will not work. since the javascript will not recognize the repeater.

     

  • Re: Container.ItemIndex and repeater.Items.Count

    05-07-2008, 8:31 AM
    • Loading...
    • chandan.max
    • Joined on 03-28-2008, 6:37 AM
    • India
    • Posts 172

     repeater1.items[repeater.items.count - 1] will work with perfection. Dont complicate the issue unneccessary

    "Mark as Answer" on the post that helped you.

    Chandan,
    Imfinity India Pte Ltd.
  • Re: Container.ItemIndex and repeater.Items.Count

    05-07-2008, 10:32 AM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7
    That does not work either. I only care if it matches the repeaters count.
  • Re: Container.ItemIndex and repeater.Items.Count

    05-07-2008, 10:36 AM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7

    Something different being not add the containers value for example

    first row output zero since I know it is zero and output repeater count

    0,7

    the rest can be this

    1,2

    2,3

    3,4

    4,5

    5,6

    6, I need zero here <-- something different

    I was using an inline IF (VB) on the ascx file

  • Re: Container.ItemIndex and repeater.Items.Count

    05-07-2008, 10:42 AM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7

    first row 

    <%# iif(Container.ItemIndex = 0, Container.ItemIndex, 0>

    each subsequent row(s)

    <%# iif(Container.ItemIndex < repeater.Items.Count -1, Container.ItemIndex, Container.ItemIndex + 1)%>

    last row (which is my main problem)

    <%# iif(Container.ItemIndex = repeater.Items.Count -1, Container.ItemIndex, repeater.Items.Count -1)%>

  • Re: Container.ItemIndex and repeater.Items.Count

    05-07-2008, 6:46 PM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7

    This works fine when I add the number 6 

    <%# iif(Container.ItemIndex = 6, Container.ItemIndex, repeater.Items.Count -1)%>

     Keep in mind my page outputs the value of repeater.Items.Count -1, which is 6 too.

  • Re: Container.ItemIndex and repeater.Items.Count

    05-09-2008, 2:08 AM
    Answer

    Hi splitfire ,

    see my sample,

     

        protected void Repeater1_PreRender(object sender, EventArgs e)
        {
            for (int i = 0; i < Repeater1.Items.Count; i++)
            {
                Label lbl1 = Repeater1.Items[i].FindControl("Label1") as Label;
                Label lbl2 = Repeater1.Items[i].FindControl("Label2") as Label;
    
                lbl1.Text = i.ToString();
                lbl2.Text = Convert.ToString (Repeater1.Items.Count - i);
            }
        }
      
           <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
                SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnPreRender="Repeater1_PreRender">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:Label ID="Label2"
                    runat="server" Text="Label"></asp:Label>
            </ItemTemplate>
            </asp:Repeater>

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Container.ItemIndex and repeater.Items.Count

    05-09-2008, 8:18 AM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7

    I'll give this a try and see what I come up with.

  • Re: Container.ItemIndex and repeater.Items.Count

    05-09-2008, 7:51 PM
    • Loading...
    • splitfire
    • Joined on 12-09-2003, 5:34 AM
    • Posts 7
    Samu Zhang, thanks for your help on this. I did have to do some extra things to get it to work in my situation, but you put in my the right direction.
Page 1 of 1 (10 items)