title: Listview is losing data on postback ASP.Net
body: <p>I am trying to update the whole list by once by using a button but in code behind I am losing the data of the list items it returns null although it has the items. Please help me in this manner. my code is below</p>
  
  <p><strong>aspx</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;asp:ListView ID="ProjectsList" runat="server" DataKeyNames="ProjectId" DataSourceID="EntityDataSource1" ViewStateMode="Enabled"&gt; 
  
      &lt;AlternatingItemTemplate&gt;
          &lt;tr style="background-color: #FFF8DC;"&gt;
              &lt;td&gt;&lt;asp:Label ID="ProjectIdLabel" runat="server" Text='&lt;%# Eval("ProjectId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="SchoolIdLabel" runat="server" Text='&lt;%# Eval("SchoolId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="FairIdLabel" runat="server" Text='&lt;%# Eval("FairId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="CategoryIdLabel" runat="server" Text='&lt;%# Eval("CategoryId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="TitleLabel" runat="server" Text='&lt;%# Eval("Title") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="BalanceLabel" runat="server" Text='&lt;%# Eval("Balance") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:CheckBox ID="FinalistCheckBox" runat="server" Checked='&lt;%# Eval("Finalist") %&gt;' Enabled="true" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="ProjectStatusLabel" runat="server" Text='&lt;%# Eval("ProjectStatus") %&gt;' /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/AlternatingItemTemplate&gt;
  
      &lt;ItemTemplate&gt;
          &lt;tr style="background-color: #DCDCDC; color: #000000;"&gt;
              &lt;td&gt;&lt;asp:Label ID="ProjectIdLabel" runat="server" Text='&lt;%# Eval("ProjectId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;asp:Label ID="SchoolIdLabel" runat="server" Text='&lt;%# Eval("SchoolId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="FairIdLabel" runat="server" Text='&lt;%# Eval("FairId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="CategoryIdLabel" runat="server" Text='&lt;%# Eval("CategoryId") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="TitleLabel" runat="server" Text='&lt;%# Eval("Title") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="BalanceLabel" runat="server" Text='&lt;%# Eval("Balance") %&gt;' /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:CheckBox ID="FinalistCheckBox" runat="server" Checked='&lt;%# Eval("Finalist") %&gt;' Enabled="true" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;asp:Label ID="ProjectStatusLabel" runat="server" Text='&lt;%# Eval("ProjectStatus") %&gt;' /&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-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px; font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;
                          &lt;tr runat="server" style="background-color: #DCDCDC; color: #000000;"&gt;
                              &lt;th runat="server"&gt;ProjectId&lt;/th&gt;
                              &lt;th id="Th1" runat="server"&gt;SchoolId&lt;/th&gt;
                              &lt;th id="Th2" runat="server"&gt;FairId&lt;/th&gt;
                              &lt;th id="Th3" runat="server"&gt;CategoryId&lt;/th&gt;
                              &lt;th runat="server"&gt;Title&lt;/th&gt;
                              &lt;th id="Th4" runat="server"&gt;Balance&lt;/th&gt;
                              &lt;th runat="server"&gt;Finalist&lt;/th&gt;
                              &lt;th runat="server"&gt;ProjectStatus&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;tr runat="server"&gt;
                  &lt;td runat="server" style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000;"&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/LayoutTemplate&gt;
  &lt;/asp:ListView&gt;
  
  &lt;asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=MyEntity" DefaultContainerName="MyEntity" EnableFlattening="False" EnableUpdate="True" EntitySetName="Projects"&gt;
  &lt;/asp:EntityDataSource&gt;
  &lt;asp:Button ID="FinalistButton" runat="server" Text="Finalist" OnClick="FinalistButton_Click" CssClass="imageButtonStyle" /&gt;
  </code></pre>
  
  <p>and my aspx.cs...</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected void FinalistButton_Click(object sender, EventArgs e)
  {
      //here I can have all the items but there is no value
      foreach (ListViewItem item in ProjectsList.Items) 
      {
          if (item.ItemType == ListViewItemType.DataItem)
          {
              CheckBox final = (CheckBox)item.FindControl("Finalist");
              TextBox proidText = (TextBox)item.FindControl("ProjectId");
              int proId = Convert.ToInt32(proidText.Text);
              if (final.Checked)  
              {
                  //some code
              }
          }
  
      }
  }
  </code></pre>