views:

44

answers:

2

I'm using Model-View-Presenter framework. When Loading a page, I'm having trouble setting the selected item that came from the Database.

In view, I know I need:

protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
    presenter.DdlStatusSelectedIndexChanged();
// what should this pass?
}

Then in Presenter:
public void DdlStatusSelectedIndexChanged()
{
   view.DdlStatus = ???
// Should I pass the SelectedIndex?
}

I also think that part of my problem is that DdlStatus I have as a List. Interface:

List<StatusDTO> DdlStatus { set; get; }

Does anybody have some simple examples of this? The best I found is here (but needs formatted!) ---> http://codebetter.com/blogs/jeremy.miller/archive/2006/02/01/137457.aspx

Thanks!

A: 

Hey,

Which framework are you using? The typical way the presenter/view relationship works is through events; the view defines events that the presenter attaches to, to receive those state change notifications. There are other options too.

Your model should contain the list of statuses and the selected status. Depending on the "flavor" of MVP, you would either have the presenter call a property on the view to pass it the selected index, and your view would pass it to the control, or the view takes the index from the model directly.

HTH.

Brian
I'm using .NET 3.5. Let me get together more code.
Patrick From An IBank
Are you using the webformsmvp product, or your own implementation?
Brian
A: 

I figured this out. It's a bit of a cheese but ...

public int DdlStatusSelectedIndex { set { for (int i = 0; i < ddlStatus.Items.Count; i++) {

            if (ddlStatus.Items[i].Value.Equals(value.ToString()))
            {
                ddlStatus.SelectedIndex = value;
            }
        }
    }
}
Patrick From An IBank