0

I have written code for simple repeater control in asp.net the repeater binding the data correctly but rendering is missing some data !!

there is my code :

<asp:Repeater ID="dayRepeater"  runat="server" >
                    <HeaderTemplate>
                        <table id="tes-table"  width="100%"  border="0" 
cellspacing="0" cellpadding="0">
                        <tr >
                            <th >Column1</th>
                            <th >Column2</th>
                            <th >Column3</th> 
                            <th >OFF_PEAK</th>
                        </tr>

                    </HeaderTemplate>

                    <ItemTemplate>
                           <tr >
                            <td><%# Eval("DayName") %></td>

                        </tr>

                    </ItemTemplate>

                    <AlternatingItemTemplate>

                    </AlternatingItemTemplate>

                    <FooterTemplate>
                        </table>
                    </FooterTemplate>
                </asp:Repeater>

**And this is the behind code in Page_Load :

private readonly string[] _daysText = {
    DaysOfWeek.SATURDAY.ToString(),
    DaysOfWeek.SUNDAY.ToString(),
    DaysOfWeek.MONDAY.ToString(),
    DaysOfWeek.TUESDAY.ToString(),
    DaysOfWeek.WEDNESDAY.ToString(),
    DaysOfWeek.THURSDAY.ToString(),
    DaysOfWeek.FRIDAY.ToString(),
 };
 for (int j = 0; j < _daysText.Length; j++)
        {
            repeaterModel.Add(new TesRepeaterDataSource
            {
                DayName = _daysText[j],

            });
        }
  dayRepeater.DataSource =repeaterModel;
  dayRepeater.DataBind();

**The data binding correctly :

The Binding the binding

The Final View the final view

Notes : I tried to binding data in page_init but the same the browser doesn't show any data so it is not hidden from css

1 Answer 1

1

The items with an uneven index (1:Sunday, 3:Tuesday, 5:Thursday) get handled by the AlternatingItemTemplate.
This AlternatingItemTemplate contains no binding expression, so nothing gets rendered.

Either remove this AlternatingItemTemplate tag, so that all items get rendered by the ItemTemplate.

Or add a binding expression into the AlternatingItemTemplate:

<AlternatingItemTemplate>
    <tr><td><%# Eval("DayName") %></td></tr>
</ItemTemplate>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.