Nicolas De Irisarri
Nicolas De Irisarri

Reputation: 1077

MVP on Asp.Net WebForms

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???

Upvotes: 4

Views: 2825

Answers (2)

Stuart McLaughlin
Stuart McLaughlin

Reputation: 171

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.

Upvotes: 3

Steve Wright
Steve Wright

Reputation: 2511

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.

Upvotes: 4

Related Questions