This is a migrated thread and some comments may be shown as answers.

NeedDataSource Question

1 Answer 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Valentine
Top achievements
Rank 2
John Valentine asked on 01 Apr 2010, 04:54 AM
Hey all,

I have been very busy lately working on a new project that uses MVP. We are plugging along and everything was going very nicely until we got to our event viewer page in our admin menu. We are using a custom implementation of the standard .NET 2.0 web event schema that we built using the MVP pattern. I want to use a RadGrid for the main display because it is a nice package for our requirements (toggle, click to expand, etc). This brings me to the problem. With MVP, the user interface is extremely thin. We built the classes and code using TDD best practices, and unfortunately, we didn't do our homework on the RadGrid very well. We mistakenly counted the NeedDataSource event as a standard EventHandler (like most other event delegates that perform data binding). What could we do to resolve this problem? Keep in mind that the obvious solution (adding the Telerik.Web.UI reference to my presenter, and model projects) is absolutely out of the question.

View Interface
public interface IEventViewerView 
        event EventHandler StartUp; 
        event EventHandler NeedDataSource; 
        object DataSource { set; } 
        object OnNeedDataSource { set; } 

Presenter Class
public class EventViewerPresenter 
        private readonly IEventViewerView _view; 
        private readonly IEventViewerRepository _repo; 
 
        public EventViewerPresenter(IEventViewerView view) : this(view, new EventViewerRepository()) 
        { 
 
        } 
 
        public EventViewerPresenter(IEventViewerView view, IEventViewerRepository repo) 
        { 
            if (view == null) 
                throw new ArgumentNullException("view may not be null"); 
            if (repo == null) 
                throw new ArgumentNullException("repo may not be null"); 
            _view = view; 
            _repo = repo; 
            _view.NeedDataSource += new EventHandler(_view_NeedDataSource); 
            _view.StartUp += new EventHandler(_view_StartUp); 
        } 
 
        void _view_NeedDataSource(object sender, EventArgs e) 
        { 
            _view.OnNeedDataSource = _repo.List(); 
        } 
 
        void _view_StartUp(object sender, EventArgs e) 
        { 
            _view.DataSource = _repo.List(); 
        } 

Here is where things go sideways. I get the following error in the code below. Cannot implicitly convert type 'System.EventHandler' to 'Telerik.Web.UI.GridNeedDataSourceEventHandler'.
protected void Page_Load(object sender, EventArgs e) 
        _presenter = new EventViewerPresenter(this); 
        grdEvents.NeedDataSource += NeedDataSource; // Errors here... 
        if (StartUp != null) StartUp(this, EventArgs.Empty); 
 
public event EventHandler StartUp; 
public event EventHandler NeedDataSource; 
 
public object DataSource 
        set  
        { 
            if (!IsPostBack) 
            { 
                grdEvents.DataSource = value
                grdEvents.DataBind(); 
            } 
        } 
 
public object OnNeedDataSource 
        set { grdEvents.DataSource = value; } 

I am having trouble figuring out how to solve this without breaking the rules for MVP.

I love these engineering challenges, but this one has me pretty well stumped.

Any Thoughts?

Thanks,

John

1 Answer, 1 is accepted

Sort by
0
John Valentine
Top achievements
Rank 2
answered on 01 Apr 2010, 05:24 AM
You know - I love how you guys think!

protected void Page_Load(object sender, EventArgs e) 
        _presenter = new EventViewerPresenter(this); 
        grdEvents.NeedDataSource += new GridNeedDataSourceEventHandler(NeedDataSource); 
        if (StartUp != null) StartUp(this, EventArgs.Empty); 

Adding my event to the constructor of the GridNeedDataSourceEventHandler seems to have done the trick.


Tags
Grid
Asked by
John Valentine
Top achievements
Rank 2
Answers by
John Valentine
Top achievements
Rank 2
Share this question
or