title: Listview not fully updating on databind() after postback
body: <p>I have a ListView control which is exhibiting an odd behaviour - rows are only partially updating after a postback.  I'm hoping someone here can shed some light on why this might be occuring.</p>
  
  <p>My listview DataSource is bound to a List of items which is stored in the page session state.  This is intentional, partially to timeout out-of-date views since multiple users view the data.  On a plain resort operation, the sorting is handled on page via javascript, and the list/session data order is kept in sync via callbacks.  Callback also checks for permissions levels.  On a particular resort operation that is more complicated, the javascript on the page makes a postback to the page to handle the sorting logic.  The List/Session is updated as in the callback, then the listview control is rebound to the data.  The page loads again, and the rows show the new order.  No problem, right?</p>
  
  <p>The problem is that <strong><em>some</em></strong> of the elements in the listview do not change value in accordance with the new order.  While the hyperlinks and text that is processed on page (ie like &lt;%# Eval("ProjectAbbrev") %>) are updated appropriately, checkboxes, literals, and dropdowns that have their values set via the OnItemDataBound event method are not - they stay "frozen" in place, even though stepping through the code reveals that the method is run during the postback, and that the controls SHOULD be set to their new values.  If I go and manually truncate the list to say, half the original size, sure enough only those items are repopulated, but the checkboxes and such still retain their original values.</p>
  
  <p>So my question is: Why aren't these elements updating along with the rest of the listview control elements on the postback?  I have the feeling that I'm either misunderstanding the page lifecycle in ASP.NET or that I've encountered a bug of some kind.</p>
  
  <p>At this point I'm thinking I will have to move the more complicated sorting operation to the page in javascript, but that will be rather tricky and I'd like to avoid doing so if possible.
  <hr/>
  UPDATE: I have tried setting EnableViewState to false and it does not fix this.  I couldn't use that tactic in any case because other parts of the page (save) rely on reading the viewstate in the end.
  <hr/>
  UPDATE: I'm providing some code snippets in the hope that they might shed some light on this issue: </p>
  
  <p>Page: The HyperLink element will update properly after postback, but the CheckBox which has its value assigned in the OnQueueRepeater_ItemDataBound method, will stay the same. </p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TextProcessorProjects.ascx.cs" Inherits="ETD.UI.Controls.TextProcessorProjects" %&gt;
  
  &lt;asp:ListView ID="QueueListView" runat="server" OnItemDataBound="OnQueueRepeater_ItemDataBound"&gt;
   &lt;ItemTemplate&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;asp:HyperLink runat="server" ID="ProjectIDLink"&gt;&lt;%# Eval("ProjectAbbrev") %&gt;&lt;/asp:HyperLink&gt;&lt;/td&gt;
     &lt;td&gt;&lt;asp:CheckBox runat="server" ID="ScannedCheckBox" BorderStyle="None" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
   &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>Code behind: On postback, the following code executes:</p>
  
  <pre><code>protected List&lt;Book&gt; QueueDataItems
  {
   get { return (List&lt;Book&gt;)Session["Queue"]; }
   set { Session["Queue"] = value; }
  }
  
  else if (IsPostBack &amp;&amp; !Page.IsCallback)
  {
   // resort QueueDataItems List appropriately
   ResortQueue(Request.Params) 
   // rebind
   QueueListView.DataSource = QueueDataItems;
   QueueListView.DataBind();
  }
  
  protected void OnQueueRepeater_ItemDataBound(object sender, ListViewItemEventArgs e)
  {
   // ...
   // ... other controls set
   CheckBox scannedCheckBox = e.Item.FindControl("ScannedCheckBox") as CheckBox;
   scannedCheckBox.Checked = book.Scanned;
  }
  </code></pre>
  
  <p>UPDATE:  I've given up on getting this to work and moved my sorting logic to the client side with javascript.  If anyone has any ideas as to why this odd behaviour was happening though, I'd still be very interested in hearing them!</p>