0

I have two repeaters, 1 nested within the other. The Inner Repeater contains and displays basically a grid of text boxes to allow the user it enter in sets of information.

If there are 0 items for the nested child, there is no issue. Otherwise, there will always be in increments of 4, pairs of text boxes. If there is 4 pairs we want to display all 4 pairs on 1 line, it there are 8 pairs, we need a line break between the first 4 and the second 4 pairs, and so on for 12.....

I was attempting this with purely CSS, based on the size of what the area was and the size of the boxes forcing it to put it on a new line, but is there a cleaner way of doing this with a repeater? I have noticed on some browsers and OS I run into it wrapping awkwardly.

<ItemTemplate>
<tr>
    <td>&nbsp;</td>
        <td>
            <asp:Label runat="server" ID="lbDayOfWeek"  Text='<%# DataBinder.Eval(Container.DataItem, "DayOfWeek") %>'/>
        </td>
        <td>
            <asp:Label runat="server" ID="lbDate" Text='<%# Format(DataBinder.Eval(Container.DataItem, "DateOfDay"), "MM/dd/yyyy") %>'/>
        </td>
        <td class="punches">
        <asp:Repeater runat="server" ID="Punches" DataSource='<%# DataBinder.Eval(Container.DataItem, "PunchPairs") %>'>
                <HeaderTemplate>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:TextBox runat='server' ID='Tb1' Text='<%# if(eval("InDefault")= false,DataBinder.Eval(Container.DataItem, "InTime"),"") %>' />
                    <asp:TextBox runat='server' ID='Tb2' Text='<%# if(eval("OutDefault")= false,DataBinder.Eval(Container.DataItem, "OutTime"),"") %>' />
                </ItemTemplate>
                <FooterTemplate>
                </FooterTemplate>
        </asp:Repeater>
        </td>
        <td class="Totals">
            <asp:TextBox ID="txtHours" runat="server"  Text='<%# DataBinder.Eval(Container.DataItem, "TotalHrs") %>' ReadOnly='true'/>
        </td>
    <td>&nbsp;</td>
</tr>

4
  • I only see one repeater. Where is the other one you are talking about? Sep 30, 2013 at 21:05
  • @DouglasBarbin This markup is nested inside of the parent's ItemTemplate. Sep 30, 2013 at 21:14
  • I don't think there's a clean way of doing this without dynamically generating the textboxes in groups of 4. Then you have the problems of page lifecycle destroying them on each PostBack. You may be better off breaking the details out into a "Details" area where the user selects a Repeater row, then you fill out (and generate the appropriate number of textboxes) the details. Sep 30, 2013 at 21:16
  • Without knowing what the parent is called or its type, can you check its .Count or .Length , Modulus 4 it, and insert a line break wherever needed? Sep 30, 2013 at 21:18

1 Answer 1

1

Yes you can do that with CSS with help of ItemDataBound event of the child repeater

On itemDatabound event

Private Sub Punches_DataBound(sender As Object, e As RepeaterItemEventArgs) Handles Punches.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        Dim XDiv As HtmlGenericControl = CType(e.Item.FindControl("XDiv"), HtmlGenericControl)
        XDiv.Attributes("Class") += " Item" & (e.Item.ItemIndex Mod 4)
    end if 
end sub 

and in item template of Punches

<ItemTemplate>
    <div runat="server" id="XDiv" class="Item">
        <asp:TextBox runat='server' ID='Tb1' Text='<%# if(eval("InDefault")= false,DataBinder.Eval(Container.DataItem, "InTime"),"") %>' />
        <asp:TextBox runat='server' ID='Tb2' Text='<%# if(eval("OutDefault")= false,DataBinder.Eval(Container.DataItem, "OutTime"),"") %>' />
    </div>
</ItemTemplate>

And CSS to float them

.Item{
  float:left;
}

.Item0{
  clear:both;
}
2
  • Michael, I was trying your suggestion. I am trying to setup the databind. It will only let me t bind to the first repeater and not the second nested repeater. With that, it is not finding the xdiv control. It always returns nothing. Oct 3, 2013 at 18:49
  • 1
    I have edited what your response was just slightly to reflect what I got to work from your answer. You did help to get me on the right track. Oct 3, 2013 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.