title: How to delete a Item in a ASP.NET listview and persist the datasource?
body: <p>I have a collection of objects I bind to a Listview like this:</p>
  
  <pre><code>   if (!IsPostBack)
          {
              List&lt;Equipment&gt; persons = new List&lt;Equipment&gt;
                               {new Equipment{ItemName = "Sworn", ItemCount = 7, ItemCost = 255},
                                new Equipment{ItemName = "Civ", ItemCount = 3, ItemCost = 80},
                                new Equipment{ItemName = "Civ", ItemCount = 5, ItemCost = 200}};
  
              lvMain.DataSource = persons;
  
              BindList();
          }
  </code></pre>
  
  <p>I want to Add/update/delete from this object collection and submit the final data object collection to the BL when the user saves... Rather than just delete/add/update everytime a row is changed.</p>
  
  <p>So my question is how do I maintain state for that datasource? I have tried this (delete example) </p>
  
  <pre><code>  protected void lvMain_ItemCommand(object sender, ListViewCommandEventArgs e)
      {
          switch (e.CommandName)
          {
              case "Delete":
                  {
                      ListViewDataItem lvdi = (ListViewDataItem)e.Item;
                      lvMain.Items.Remove(lvdi);                
                      break;
                  }
  </code></pre>
  
  <p>But it does nothing.  I can't rebind it to the datasrouce because at this point the datasource is null.. I assume the listview keeps its own view state which contains the data?... I guess worse case I can always hold the Object Collection in a Session object.. ..</p>
  
  <p>Am I doing something wrong or thinking the wrong way?  </p>