(21):チュートリアル(10)〜ページ(コードビハインド)の実装〜
ページ(コードビハインド)の「ViewAll.aspx.cs」にロジックを記述する。
- (1)インターフェース「IViewAll」に定義したAuthorsプロパティを実装する。
public IList<Author> Authors { set { ObjectContainerDs.DataSource = value; } }
ソースコードは次のようになる。
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.Practices.ObjectBuilder; using MyWcsf.AuthorsBL.Views; using MyWcsf.AuthorsBL.Entity; using System.Collections.Generic; public partial class AuthorsBL_ViewAll : System.Web.UI.Page, IViewAll { private ViewAllPresenter _presenter; //WCSFが生成するコードひな形 // Page_Load時にはPresenterクラスのOnViewLoadedメソッドを、 // 初期表示時にはOnViewInitializedメソッドを呼び出す protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); } this._presenter.OnViewLoaded(); } //Presenterプロパティ //(ObjectBuilderによって自動的にセットされる) [CreateNew] public ViewAllPresenter Presenter { set { this._presenter = value; this._presenter.View = this; } } //Authorsプロパティ //Page_Load時にPresenterからセットする public IList<Author> Authors { set { //ObjectContainerDataSourceコントロールのデータソースとして設定 ObjectContainerDs.DataSource = value; } } }