模型视图演示者 - 如何在下拉列表中显示所选项目?

发布于 2024-09-11 07:52:48 字数 732 浏览 3 评论 0原文

我正在使用模型-视图-演示者框架。加载页面时,我在设置来自数据库的所选项目时遇到问题。

鉴于,我知道我需要:

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

我还认为我的部分问题是我将 DdlStatus 作为列表。 界面:

List<StatusDTO> DdlStatus { set; get; }

有人有一些简单的例子吗? 我找到的最好的就在这里(但需要格式化!)---> http://codebetter.com/blogs/jeremy。米勒/archive/2006/02/01/137457.aspx

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薆情海 2024-09-18 07:52:48

您使用哪个框架?演示者/观看者关系的典型工作方式是通过事件;视图定义演示者附加的事件,以接收这些状态更改通知。还有其他选择。

您的模型应包含状态列表和所选状态。根据 MVP 的“风格”,您可以让演示者调用视图上的属性以将选定的索引传递给它,并且您的视图将其传递给控件,​​或者视图直接从模型获取索引。

HTH。

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.

黯然#的苍凉 2024-09-18 07:52:48

我明白了这一点。它有点像奶酪,但是......

public int DdlStatusSelectedIndex
{   
  set
  {
     for (int i = 0; i < ddlStatus.Items.Count; i++)
     {
        if (ddlStatus.Items[i].Value.Equals(value.ToString()))
        {
           ddlStatus.SelectedIndex = value;
        }
     }
  }
}

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;
        }
     }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文