title: ASP.NET ListView control not firing OnItemCommand Event
body: <p>I know that this sounds like a number of other posts, all of which I have read but have not addressed my issue.</p>
  
  <p>Here's the Scenario ... </p>
  
  <p>I have BOTH a Repeater and a ListView bound to the same Data Source. Each control contains an ASP:LinkButton which, when clicked, should fire the OnItemCommand event. Although they are wired to the EXACT same data at the EXACT same places in the page life cycle and View State is enabled for the page and each individual control the Repeater appears to fire the event and the ListView does not. </p>
  
  <p>I know that the event will not fire if the data is not bound BEFORE the assignment of the event handler. I am relying on ViewState to repopulate the controls when the page is posted back to. Looking at each control in debug mode while stepping through a request I can see that the Repeater DOES indeed appear to repopulated with the ViewState data but the ListView does not. </p>
  
  <p>As these are both generated, populated, bound, and handled almost IDENTICALLY I am at a complete loss why this may be happening. I have also noticed a similar issue with the GridView control (it does NOT fire the event). I assume that these are related somehow. </p>
  
  <p>The only thing that I can think of that the GridView and ListView have in common that the Repeater does not is the built-in paging capability. Whether implemented or not is there something with the paging that affects the loading of the ViewState?</p>
  
  <p><em><strong>OrderControl.ASCX</em></strong> is a control which exposes the ListView and Repeater as properties (OrderListLV &amp; OrderListRPT) to the host page/application.</p>
  
  <pre><code>    &lt;asp:ListView runat="server" id="lvOrderList" OnItemDataBound="lstOrderList_OnItemDataBound" EnableViewState="true" &gt;
      &lt;LayoutTemplate&gt;
          &lt;table class="tblGrid"&gt;
          &lt;tr runat="server" id="itemPlaceholder" /&gt;
          &lt;/table&gt;
          &lt;ASP:DataPager runat="server" ID="dataPager1" PageSize="3"&gt;
          &lt;Fields&gt;
              &lt;ASP:NextPreviousPagerField 
                   ButtonType="Button" 
                   ShowFirstPageButton="true"
                   ShowLastPageButton="true"
                   ShowNextPageButton="true"
                   ShowPreviousPageButton="true" /&gt;
          &lt;/Fields&gt;
          &lt;/ASP:DataPager&gt;
      &lt;/LayoutTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;tr class="row-"&gt;
              &lt;td align="center"&gt;&lt;ASP:LinkButton runat="server" id="lnkOrderId1" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
      &lt;/asp:ListView&gt; 
  
  
      &lt;asp:Repeater runat="server" id="rptOrderList" OnItemDataBound="rptOrderList_ItemDataBound"&gt;
      &lt;HeaderTemplate&gt;
          &lt;table class="tblGrid"&gt; 
      &lt;/HeaderTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;tr"&gt;
              &lt;td align="center"&gt;&lt;ASP:LinkButton runat="server" id="lnkOrderId" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
  
      &lt;FooterTemplate&gt;
          &lt;/table&gt;
      &lt;/FooterTemplate&gt;
      &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p><em><strong>OrderControl.ASCX.CS</em></strong> is where the controls are bound to the data source in the Pre-Render stage, well after ViewState has had the opportunity to reconstitute itself.</p>
  
  <pre><code>    protected override void OnPreRender(EventArgs e)
      {
          this.lstOrderList.DataSource = this.OrderHeaders.OrderByDescending(x =&gt; x.OrderDate).ToList();
          this.lstOrderList.DataBind();
  
          this.rptOrderList.DataSource = this.OrderHeaders.OrderByDescending(x =&gt; x.OrderDate).ToList();
          this.rptOrderList.DataBind();
      }
  </code></pre>
  
  <p><em><strong>Host.ASPX.CS</em></strong> is the page which consumes the control. It attaches the event handlers directly the controls in it's OnLoad handler.</p>
  
  <pre><code>    protected override void OnLoad(EventArgs e)
      {
          base.OnLoad(e);
  
          this.OrderControl.OrderListRPT.ItemCommand    += new RepeaterCommandEventHandler(OrderList2_ItemCommand);
          this.OrderControl.OrderListLV.ItemCommand     += new EventHandler&lt;ListViewCommandEventArgs&gt;(OrderList_ItemCommand);
  
      }
  </code></pre>
  
  <p>After all is said and done when I click on the LinkButton in each control the ItemCommand Handler for the Repeater fires and executes correctly but the process doesn't even enter the handler for the ListView handler. </p>
  
  <p>I am crazy confused on this issue. I am hoping that someone might have some thoughts on this. Something I can try at least?</p>
  
  <p>Thanks,
  Gary </p>