4

I'm not clear about this....

When having a gridview on the View, is the controller who has to set up the Data source, columns, etc? or I just have to expose the DataBinding stuff, fire it from the controller and let the html/codebehind on the view handle all the rendering and wiring up?

To be more precise: on the view should I have

private GridView _gv
public _IList<Poco> Source { 
    get {_gv.DataSource;}
    set {_gv.DataSource = value;
         _gv.DataBind();}
}

Or should it be (from MVP pattern - Passive View and exposing complex types through IView (Asp.Net, Web Forms))

private GridView _datasource;
public DataSource 
{
  get { return _datasource; }
  set 
  { 
    _datasource = value; 
    _datasource.DataBind(); 
  }
}

Maybe I'm having it all wrong ....

Where can I find an example that is not a "Hello world" example on MVP for ASP.Net???

Community
  • 1
  • 1
Nicolas De Irisarri
  • 1,077
  • 1
  • 14
  • 27

2 Answers2

4

Your controller should be in charge of setting the "result" of the databinding. The view is in charge of displaying it propertly.

So for example, your webform/usercontrol (View) could have the data source exposed as an object property that your View should know how to handle when it receives it:

public MyObject DataSource 
{
  set 
  { 
    _datasource = value; 
    _datasource.DataBind(); 
  } 
}

So if you need to have an ItemDataBound event, I would still handle it in the view. Even though there could be business logic in the event. If you need to have business logic in the event, I would put it in the MyObject result before it is passed to the view.

So an example would be to have a property of "MyObject" be "AllowDelete" and in your ItemDataBound, the value of this property determines if a column in the GridView is enabled or not.

Steve Wright
  • 2,481
  • 3
  • 26
  • 35
3

Having just listened to a recent Hanselminutes on this topic, it might be worth having a look at the http://webformsmvp.com/ project, which seems to bring a bit of rigidity into separating concerns within WebForms.