Traverse GridView in the View or the Presenter?

Topics: Web Client Software Factory
Oct 22, 2007 at 7:59 AM
Hi everyone. First, I just want to say that I have really enjoyed building my first application with the WCSF. I think it is a great tool. Now, onto my question: I have created a project where I need to loop through my gridview and do something. In my view I have something like the following:

private void SomeEvent()
{
foreach (GridViewRow gvr in GridView1.Rows)
{
// do something here
}
}

My question is whether this is the correct place to do this or should I pass my GridView to the presenter and do whatever I need to do? For example, in my view:

private void SomeEvent()
{
// Pass gridview to presenter
_presenter.OnSomeEvent(GridView1);
}

Then in my presenter:

public void OnSomeEvent(GridView GridView1)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
// do something here
}
}
Oct 22, 2007 at 9:20 AM
Hi, I think that the GridView is a UI component and the presenter should know whether the View use a GridView or some third party user control.
I think that the best way is to collect the needed data in the view and pass it to the presenter.

private void SomeEvent()
{
foreach (GridViewRow gvr in GridView1.Rows)
{
// var myParam
_presenter.OnSomeEvent(myParam);
}
}

Or you can collect all the data in the loop and pas it to the presenter at once.
Oct 22, 2007 at 9:08 PM
So, it sounds like you are saying that the Presenter should not have any knowledge of any UI components. If this is the case, I will leave my logic in the View since I am basically just manipulating UI components where I have listed "do something here". Specifically, I am implementing client side "checkAll" functionality for a gridview based on Scott Mitchell's example: http://aspnet.4guysfromrolla.com/articles/053106-1.aspx.

foreach (GridViewRow gvr in GridView1.Rows)
{
//Get a programmatic reference to the CheckBox control
CheckBox cb = (CheckBox)gvr.FindControl("RowLevelCheckBox");

//If the checkbox is unchecked, ensure that the Header CheckBox is unchecked
cb.Attributes"onclick" = "ChangeHeaderAsNeeded();";
...

Thanks for your help!

Jared
Oct 24, 2007 at 9:34 AM
I think that checking and unchecking is a pure UI operation and you don’t need to call the presenter for that operation. Someone could implement the grid without the checkboxs, he just add a button in each row.

The idea behind the presenter is that we can export it to be used in Windows Forms Application, or other kind of client.