What i'm I missing?
My line "foreach (ProductCrash productCrash in _fiveLastest)
" is wrong, but I can't see any alternatives. I wont to get ride out the foreach and let the ListView do its magic for me.. does any know how to do this? It would really help me out.
I can only show one object from my list in my ListView. I'm using ObjectDataSource to bind my list with the ListView, and don't want to change that.
In my ascx.cs fil i retrieve the List _fiveLastest, with Entity.
private List<ProductCrash> _fiveLastest;
protected void Page_Load(object sender, EventArgs e)
{
index = 0;
_dataAccess = new DataAccess();
_fiveLastest = _dataAccess.TimeStampForCrashByIndex();
_fiveLastest.Sort((x, y) => y.CrashTimeStamp.CompareTo(x.CrashTimeStamp));
}
protected void ListView2_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
foreach (ProductCrash productCrash in _fiveLastest)
{
Label statusLabel = (Label)e.Item.FindControl("TimeStampLabel");
Label productIDLabel = (Label)e.Item.FindControl("ProductIDLabel");
if (index < _fiveLastest.Count)
{
productIDLabel.Text = productCrash.ProductName;
statusLabel.Text = DatetimeHelper.MyDateTimeFormat(productCrash.CrashTimeStamp);
}
}
}
}
=========
Here's a codesnippet of my ListView, ItemTemplate, LayoutTemplate and ObjectDataSource
<asp:ListView ID="ListView2" runat="server" DataSourceID="ObjectDataSource1" onitemdatabound="ListView2_ItemDataBound">
<ItemTemplate>
<tr style="background-color: #FFFFFF;color: #000000;">
<td style="padding: 5px 5px;">
<asp:Label ID="ProductIDLabel" runat="server" />
</td>
<td style="padding: 5px 5px;">
<asp:Label ID="TimeStampLabel" runat="server" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1"
style=" background-color: #FFFFFF;border-color: #999999;border-style:solid;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr id="Tr1" runat="server" style="background-color: #DCDCDC;color: #333333; text-align:left; padding: 5px 10px;">
<th runat="server" style="padding: 5px 5px; text-transform:uppercase;">
Produkt</th>
<th runat="server" style="padding: 5px 5px; text-transform:uppercase;">
Tidspunkt</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="CreateStateLog" TypeName="Website.StateLog"
UpdateMethod="CreateStateLog">
<UpdateParameters>
<asp:Parameter Name="stateLogID" Type="Int32" />
<asp:Parameter Name="productID" Type="Int32" />
<asp:Parameter Name="status" Type="Int32" />
<asp:Parameter Name="timeStamp" Type="DateTime" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="stateLogID" Type="Int32" />
<asp:Parameter Name="productID" Type="Int32" />
<asp:Parameter Name="status" Type="Int32" />
<asp:Parameter Name="timeStamp" Type="DateTime" />
</SelectParameters>
</asp:ObjectDataSource>