title: How to Bind Data and manipulate it in a GridView with MVP
body: <p>I am new to the whole MVP thing and slowly getting my head around it all. The a problem I am having is how to stay consistent with the MVP methodology when populating GridViews (and ddls, but we will tackle that later).</p>
  
  <p>Is it okay to have it connected straight to an ObjectDataSourceID? To me this seems wrong because it bypasses all the separation of concerns MVP was made to do. </p>
  
  <p>So, with that said, how do I do it? How do I handle sorting (do I send over handler events to the presentation layer, if so how does that look in code)?
  Right now I have a GridView that has no sorting. Code below.</p>
  
  <p>ListCustomers.aspx.cs:</p>
  
  <pre><code>public partial class ListCustomers : System.Web.UI.Page, IlistCustomer
  {
  protected void Page_Load(object sender, EventArgs e)
  {
      //On every page load, create a new presenter object with
      //constructor  recieving the 
  
      //  page's IlistCustomer view 
      ListUserPresenter ListUser_P = new ListUserPresenter(this);
  
      //Call the presenter's PopulateList to bind data to gridview
      ListUser_P.PopulateList();
  
  }
  
  GridView IlistCustomer.UserGridView
  {
      get { return gvUsers; }
      set { gvUsers = value; }
  }
  
  }
  </code></pre>
  
  <p>Interface ( IlistCustomer.cs): is this bad sending in an entire Gridview control?</p>
  
  <pre><code>public interface IlistCustomer
  {
  GridView UserGridView { set; get; }
  }
  </code></pre>
  
  <p>The Presenter (ListUserPresenter.cs):</p>
  
  <pre><code>public class ListUserPresenter
  {
  private IlistCustomer view_listCustomer;
  private GridView gvListCustomers;
  private DataTable objDT;
  
  public ListUserPresenter( IlistCustomer view)
  {
      //Handle an error if an Ilistcustomer was not sent in)
      if (view == null)
          throw new ArgumentNullException("ListCustomer View cannot be blank");
  
      //Set local IlistCustomer interface view
      this.view_listCustomer = view;
  }
  
  public void PopulateList()
  {
      //Fill local Gridview with local IlistCustomer
      gvListCustomers = view_listCustomer.UserGridView;
  
      // Instantiate a new CustomerBusiness object to contact database
      CustomerBusiness CustomerBiz = new CustomerBusiness();
  
      //Call CustomerBusiness's GetListCustomers to fill DataTable object
      objDT = CustomerBiz.GetListCustomers();
  
      //Bind DataTable to gridview;
      gvListCustomers.DataSource = objDT;
      gvListCustomers.DataBind();
  }
  }
  </code></pre>