title: How to fill a ListView with a list using ObjectDataSource
body: <p>What i'm I missing?</p>
  
  <p>My line "<code>foreach (ProductCrash productCrash in _fiveLastest)</code>" is wrong, but I can't see any alternatives. I wont to get ride out the foreach and let the ListView <em>do its magic for me</em>.. does any know how to do this? It would really help me out.</p>
  
  <p>I can only show <em>one</em> 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.</p>
  
  <p>In my ascx.cs fil i retrieve the List <strong>_fiveLastest</strong>, with Entity.</p>
  
  <pre><code>    private List&lt;ProductCrash&gt; _fiveLastest; 
  
      protected void Page_Load(object sender, EventArgs e)
      {
          index = 0;
          _dataAccess = new DataAccess();
          _fiveLastest = _dataAccess.TimeStampForCrashByIndex();
          _fiveLastest.Sort((x, y) =&gt; 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 &lt; _fiveLastest.Count)
                  {
                      productIDLabel.Text = productCrash.ProductName;
                      statusLabel.Text = DatetimeHelper.MyDateTimeFormat(productCrash.CrashTimeStamp); 
                  }
              }
          }
      }
  </code></pre>
  
  <p>=========</p>
  
  <p>Here's a codesnippet of my ListView, ItemTemplate, LayoutTemplate and ObjectDataSource</p>
  
  <pre><code>&lt;asp:ListView ID="ListView2" runat="server" DataSourceID="ObjectDataSource1"     onitemdatabound="ListView2_ItemDataBound"&gt;
  
  &lt;ItemTemplate&gt;
      &lt;tr style="background-color: #FFFFFF;color: #000000;"&gt;
          &lt;td  style="padding: 5px 5px;"&gt;
              &lt;asp:Label ID="ProductIDLabel" runat="server" /&gt;
          &lt;/td&gt;
          &lt;td  style="padding: 5px 5px;"&gt;
              &lt;asp:Label ID="TimeStampLabel" runat="server" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/ItemTemplate&gt; 
  
  &lt;LayoutTemplate&gt;
      &lt;table runat="server"&gt;
          &lt;tr runat="server"&gt;
              &lt;td runat="server"&gt;
                  &lt;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;"&gt;
                      &lt;tr id="Tr1" runat="server" style="background-color: #DCDCDC;color: #333333; text-align:left; padding: 5px 10px;"&gt;
                          &lt;th runat="server" style="padding: 5px 5px; text-transform:uppercase;"&gt;
                              Produkt&lt;/th&gt;
                          &lt;th runat="server" style="padding: 5px 5px; text-transform:uppercase;"&gt;
                              Tidspunkt&lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;tr ID="itemPlaceholder" runat="server"&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
      &lt;/table&gt;
  &lt;/LayoutTemplate&gt;
  
  &lt;asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
  SelectMethod="CreateStateLog" TypeName="Website.StateLog" 
  UpdateMethod="CreateStateLog"&gt;
  &lt;UpdateParameters&gt;
      &lt;asp:Parameter Name="stateLogID" Type="Int32" /&gt;
      &lt;asp:Parameter Name="productID" Type="Int32" /&gt;
      &lt;asp:Parameter Name="status" Type="Int32" /&gt;
      &lt;asp:Parameter Name="timeStamp" Type="DateTime" /&gt;
  &lt;/UpdateParameters&gt;
  &lt;SelectParameters&gt;
      &lt;asp:Parameter Name="stateLogID" Type="Int32" /&gt;
      &lt;asp:Parameter Name="productID" Type="Int32" /&gt;
      &lt;asp:Parameter Name="status" Type="Int32" /&gt;
      &lt;asp:Parameter Name="timeStamp" Type="DateTime" /&gt;
  &lt;/SelectParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>