Reputation: 25
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 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
Upvotes: 0
Views: 351
Reputation: 23214
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>
Upvotes: 1