title: ASP.NET ListView, custom DataSources, and editing items
body: <p>The MSDN walkthroughs provide a number of examples where you can drag a DataSource from the toolbox, run through some simple configuration steps, then drag a <A HREF="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.aspx" rel="nofollow noreferrer">ListView</A> onto the screen, point it at the DataSource, and hey - you've got full table editing. </p>
  
  <p>Now I'm trying to write my own DataSource class (a class that implements <A HREF="http://msdn.microsoft.com/en-us/library/system.web.ui.idatasource.aspx" rel="nofollow noreferrer"><i>System.Web.UI.IDataSource</i></A>) and my own DataSourceView class. I now assign an instance of this custom DataSource class to the <A HREF="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.datasource.aspx" rel="nofollow noreferrer"><i>ListView.DataSource</i></A> propery.</p>
  
  <p>The display of all the items is working well. However, updating, inserting and deleting just is not working. I'm overriding every function I can in my DataSourceView class, and they just aren't being called.</p>
  
  <p>This is such a huge topic, I'll focus this question on one simple example:</p>
  
  <p>When you press the "Edit" button (the button inside the <i>ItemTemplate</i> with a <i>CommandName</i> of "Edit", you expect the <i>ItemTemplate</i> to be replaced by an <i>EditItemTemplate</i>. This did not happen. The only way I could get it to happen was to handle the <i>onitemediting</i> event.</p>
  
  <pre><code>protected void _listViewPublicHolidays_ItemEditing(object sender, ListViewEditEventArgs e)
  {
      _listViewPublicHolidays.EditIndex = e.NewEditIndex;
      _listViewPublicHolidays.DataBind();
  }
  </code></pre>
  
  <p>This is hardly a problem, but how come I had to do it at all? In the MSDN walkthroughs where I attach a <i>ListView</i> to a <i>LinqDataSource</i>, this code doesn't have to be written. Can someone who's been here before hazard a guess as to what would be different or missing in my custom datasource?</p>