title: ItemCommand Update and ItemUpdating are not working in ListView
body: <p>I can't seem to get my Listview update commands to work. Here is my datagrid:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;asp:ListView ID="lvECOItems" runat="server" 
      EnableViewState="False" DataKeyNames="ID,ECOID"
      onitemupdating="lvECOItems_ItemUpdating" 
      EnableModelValidation="True" 
      onitemcommand="lvECOItems_ItemCommand" 
      onitemcanceling="lvECOItems_ItemCanceling" 
      onitemdeleting="lvECOItems_ItemDeleting" 
      onitemediting="lvECOItems_ItemEditing"&gt;
      &lt;AlternatingItemTemplate&gt;
          &lt;div class="listViewRow" style="border-bottom: solid 1px #C0C0C0; background-color: #fff; padding-top: 5px; padding-bottom: 5px;"&gt;
              &lt;table style="width: 100%;" class="data-table"&gt;
                  &lt;tr&gt;
                      &lt;td style="width: 3%;"&gt;&lt;asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt;&lt;/td&gt;
                      &lt;td style="width: 8%;"&gt;&lt;asp:Label ID="DocumentNumber" runat="server" Text='&lt;%# Eval("DocumentNumber") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 10%;"&gt;&lt;asp:Label ID="title" runat="server" Text='&lt;%# Eval("Title") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 2%; text-align:center;"&gt;&lt;asp:Label ID="RevisionFrom" runat="server" Text='&lt;%# Eval("RevisionFrom") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 2%; text-align:center;"&gt;&lt;asp:Label ID="To" runat="server" Text='&lt;%# Eval("To") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 1%; text-align:right;"&gt;&lt;asp:ImageButton ID="btnDelete" ToolTip="Delete this record" ImageUrl="~/images/delete.jpg" runat="server" OnClientClick="return confirm('Are you sure you want to delete this record?')" CausesValidation="False" CommandName="Delete" Text="Delete"&gt;&lt;/asp:ImageButton&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;asp:Label ID="IDLabel" Visible="false" runat="server" Text='&lt;%# Eval("ID") %&gt;' &gt;&lt;/asp:Label&gt;
              &lt;asp:Label ID="ECOIDLabel" Visible="false" runat="server" Text='&lt;%# Eval("ECOID") %&gt;' &gt;&lt;/asp:Label&gt;
          &lt;/div&gt;
      &lt;/AlternatingItemTemplate&gt;
      &lt;LayoutTemplate&gt;
          &lt;div class="listViewHeader"&gt;
              &lt;table style="width: 100%; border-bottom: solid 1px #808080; border-top: solid 1px #808080;" class="data-table"&gt;
                  &lt;tr&gt;
                      &lt;td class="rowheader" style="width: 3%;"&gt;&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 8%;"&gt;&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 10%;"&gt;&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 4%; text-align:center; border-bottom: solid 1px #fff; font-style: italic;" colspan="2"&gt;Revision&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td class="rowheader" style="width: 3%;"&gt;&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 8%;"&gt;Document #&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 10%;"&gt;Title&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 2%; text-align:center;"&gt;From&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 2%; text-align:center;"&gt;To&lt;/td&gt;
                      &lt;td class="rowheader" style="width: 1%;"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
         &lt;asp:PlaceHolder runat="server" ID="itemPlaceholder"&gt;&lt;/asp:PlaceHolder&gt;
      &lt;/LayoutTemplate&gt;
      &lt;EmptyItemTemplate&gt;&lt;div&gt;&lt;/div&gt;&lt;/EmptyItemTemplate&gt;
      &lt;InsertItemTemplate&gt;&lt;/InsertItemTemplate&gt;
      &lt;SelectedItemTemplate&gt;&lt;/SelectedItemTemplate&gt;
      &lt;EmptyDataTemplate&gt;
          &lt;div class="listViewEmptyDataTemplate" style="width: 650px;"&gt;
              &lt;span&gt;
                  This list does not contain any items.
              &lt;/span&gt;
          &lt;/div&gt;
      &lt;/EmptyDataTemplate&gt;
      &lt;EditItemTemplate&gt;
          &lt;div class="listViewEditRow" style="background-color: #fff; border-top: solid 1px #000; border-bottom: solid 1px #000; padding-top: 10px; padding-left: 10px"&gt;
              &lt;asp:Label ID="IDLabel" Visible="false" runat="server" Text='&lt;%# Bind("ID") %&gt;' &gt;&lt;/asp:Label&gt;
              &lt;asp:Label ID="ECOIDLabel" Visible="false" runat="server" Text='&lt;%# Bind("ECOID") %&gt;' &gt;&lt;/asp:Label&gt;
              &lt;div style="float: left;"&gt;
                  &lt;table class="data-table"&gt;
                      &lt;tr&gt;
                          &lt;td style="width: 175px;"&gt;Document Number:&lt;/td&gt;
                          &lt;td colspan="3"&gt;&lt;asp:Textbox ID="txtDocumentNumber" Width="300px" runat="server" Text='&lt;%# Bind("DocumentNumber") %&gt;'&gt;&lt;/asp:Textbox&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="width: 175px;"&gt;Title:&lt;/td&gt;
                          &lt;td colspan="3"&gt;&lt;asp:Textbox ID="txttitle" Width="300px" runat="server" Text='&lt;%# Bind("Title") %&gt;'&gt;&lt;/asp:Textbox&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="width: 175px;"&gt;Revision From:&lt;/td&gt;
                          &lt;td&gt;&lt;asp:Textbox ID="txtRevisionFrom" Width="50px" runat="server" Text='&lt;%# Bind("RevisionFrom") %&gt;'&gt;&lt;/asp:Textbox&gt;&lt;/td&gt;
                          &lt;td&gt;To:&lt;/td&gt;
                          &lt;td&gt;&lt;asp:Textbox ID="txtTo" runat="server" Width="50px" Text='&lt;%# Bind("To") %&gt;'&gt;&lt;/asp:Textbox&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
              &lt;div class="clear" style="margin-top: 5px;"&gt;&amp;nbsp;&lt;/div&gt;
              &lt;div style="padding-bottom: 5px;"&gt;
                  &lt;asp:Button ID="LinkButton4" runat="server" Width="75px" style="margin-right: 10px;" CausesValidation="False" ValidationGroup="vgUpdate" CommandName="Update" Text="Update"&gt;&lt;/asp:Button&gt;
                  &lt;asp:Button ID="LinkButton3" runat="server" Width="75px" ForeColor="#B22222" CausesValidation="False" CommandName="Cancel" Text="Cancel"&gt;&lt;/asp:Button&gt;
              &lt;/div&gt;
              &lt;asp:RequiredFieldValidator ID="vDocumentNumber" runat="server" 
                  ControlToValidate="txtDocumentNumber" ValidationGroup="vgUpdate" Display="None" 
                  ErrorMessage="Document # is required"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;asp:ValidationSummary ID="ValidationSummary2" ValidationGroup="vgUpdate" runat="server" ShowMessageBox="True" ShowSummary="False" HeaderText="The record cannot be updated due to the following:" /&gt;
          &lt;/div&gt;
      &lt;/EditItemTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;div class="listViewRow" style="border-bottom: solid 1px #C0C0C0; background-color: #fff; padding-top: 5px; padding-bottom: 5px;"&gt;
              &lt;table style="width: 100%;" class="data-table"&gt;
                  &lt;tr&gt;
                      &lt;td style="width: 3%;"&gt;&lt;asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt;&lt;/td&gt;
                      &lt;td style="width: 8%;"&gt;&lt;asp:Label ID="DocumentNumber" runat="server" Text='&lt;%# Eval("DocumentNumber") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 10%;"&gt;&lt;asp:Label ID="title" runat="server" Text='&lt;%# Eval("Title") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 2%; text-align:center;"&gt;&lt;asp:Label ID="RevisionFrom" runat="server" Text='&lt;%# Eval("RevisionFrom") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 2%; text-align:center;"&gt;&lt;asp:Label ID="To" runat="server" Text='&lt;%# Eval("To") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                      &lt;td style="width: 1%; text-align:right;"&gt;&lt;asp:ImageButton ID="btnDelete" ToolTip="Delete this record" ImageUrl="~/images/delete.jpg" runat="server" OnClientClick="return confirm('Are you sure you want to delete this record?')" CausesValidation="False" CommandName="Delete" Text="Delete"&gt;&lt;/asp:ImageButton&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;asp:Label ID="IDLabel" Visible="false" runat="server" Text='&lt;%# Eval("ID") %&gt;' &gt;&lt;/asp:Label&gt;
              &lt;asp:Label ID="ECOIDLabel" Visible="false" runat="server" Text='&lt;%# Eval("ECOID") %&gt;' &gt;&lt;/asp:Label&gt;
          &lt;/div&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>and my <code>ItemCommand</code> event:</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected void lvECOItems_ItemCommand(object sender, ListViewCommandEventArgs e)
  {
      Label ecoItemIDLabel = (Label)e.Item.FindControl("IDLabel");
      string id = ecoItemIDLabel.Text;
      // get the list item id from the ListView
      if (!String.IsNullOrEmpty(this.ecoID) &amp;&amp; !String.IsNullOrEmpty(id))
      {
          if (e.CommandName == "Delete")
          {
              ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
              ECOItems ecoItems = new ECOItems();
              ecoItems.ECOID = this.ecoID;
              ecoItems.ID = Int32.Parse(id);
              ecoItemsRepository.Delete(ecoItems);
          }
          else if (e.CommandName == "Update")
          {
              ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
              ECOItems ecoItems = new ECOItems();
  
              Label IDLabel = (Label)e.Item.FindControl("IDLabel");
              TextBox txtDocumentNumber = (TextBox)e.Item.FindControl("txtDocumentNumber");
              TextBox txttitle = (TextBox)e.Item.FindControl("txttitle");
              TextBox txtRevisionFrom = (TextBox)e.Item.FindControl("txtRevisionFrom");
              TextBox txtTo = (TextBox)e.Item.FindControl("txtTo");
  
              ecoItems.ECOID = this.ecoID;
              ecoItems.ID = Int32.Parse(IDLabel.Text);
              ecoItems.DocumentNumber = txtDocumentNumber.Text;
              ecoItems.title = txttitle.Text;
              ecoItems.RevisionFrom = txtRevisionFrom.Text;
              ecoItems.To = txtTo.Text;
              ecoItemsRepository.Edit(ecoItems);
          }
          BindListView();
      }
  }
  </code></pre>
  
  <p>and I am even trying the <code>ItemUpdating</code> event:</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected void lvECOItems_ItemUpdating(object sender, ListViewUpdateEventArgs e)
  {
      ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
      ECOItems ecoItems = new ECOItems();
      Label IDLabel = (Label)lvECOItems.EditItem.FindControl("IDLabel");
      TextBox txtDocumentNumber = (TextBox)lvECOItems.EditItem.FindControl("txtDocumentNumber");
      TextBox txttitle = (TextBox)lvECOItems.EditItem.FindControl("txttitle");
      TextBox txtRevisionFrom = (TextBox)lvECOItems.EditItem.FindControl("txtRevisionFrom");
      TextBox txtTo = (TextBox)lvECOItems.EditItem.FindControl("txtTo");
  
      ecoItems.ECOID = this.ecoID;
      ecoItems.ID = Int32.Parse(IDLabel.Text);
      ecoItems.DocumentNumber = txtDocumentNumber.Text;
      ecoItems.title = txttitle.Text;
      ecoItems.RevisionFrom = txtRevisionFrom.Text;
      ecoItems.To = txtTo.Text;
      ecoItemsRepository.Edit(ecoItems);
  
      this.lvECOItems.EditIndex = -1;
      BindListView();
  </code></pre>
  
  <p>And finally, my binding method:</p>
  
  <pre class="lang-cs prettyprint-override"><code>protected void BindListView()
  {
      if (!String.IsNullOrEmpty(this.ecoID))
      {
          ECOItemsRepository ecoItemsRepository = new ECOItemsRepository();
          this.lvECOItems.DataSource = ecoItemsRepository.GetECOItems(ecoID);
          this.lvECOItems.DataBind();
          this.lvECOItems.Enabled = true;
      }
      else
      {
          this.lvECOItems.Enabled = false;
      }
  }
  </code></pre>
  
  <p>When I click the edit link, the ListView goes into edit mode like it should.</p>
  
  <p>When I click the update button in the <code>EditItemTemplate</code> it doesn't trigger the <code>ItemCommand</code> event. The delete and cancel both work. </p>
  
  <p>The <code>ItemUpdating</code> event does not fire at all.</p>
  
  <p>One note: This ListView is in a user control within a sharepoint webpart, so the user control is dynamically created. I have a sneaking suspicion it has to do with binding the grid on a postback. But if I don't, the listview does not populate except on the intial load of the page.</p>