勘違い

(これの続き)

別にデータバインディングは楽勝で使えた。

勘違いしてた時のコード

public sealed class LendController : Controller<ILendView>
{
    private IList<BookEntity> _lendBookEntities;

    public void AddBookEntity(string bookId, string localId)
    {
        BookEntity bookEntity = this._repository.GetBookEntityById(bookId, localId);
        if (bookEntity == null)
        {
            this.View.NotifyBookEntityNotFound();
            return;
        }
        this._lendBookEntities.Add(bookEntity);
        this.View.AdditionalDisplayBookEntityInfo(bookEntity);
    }
}

public interface ILendView : IView
{
    void AdditionalDisplayBookEntityInfo(BookEntity bookEntity);
    void NotifyBookEntityNotFound();
}

public class Lend : System.Web.UI.Page, ILendView
{
    private LendController _controller;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            SessionStateAdapter<LendController>.SetItem(new LendController(RepositoryFactory.CreateRepository()));
        }
        this._controller = SessionStateAdapter<LendController>.GetItem();
        this._controller.SetView(this);
    }

    protected void _bookEntityAddButton_Click(object sender, EventArgs e)
    {
        this._controller.AddBookEntity(this._bookIdTextBox.Text, this._bookLocalIdTextBox.Text);
    }

    void ILendView.AdditionalDisplayBookEntityInfo(BookEntity bookEntity)
    {
        this._bookEntityNotFoundMessageLabel.Visible = false;
        // データバインドで画面表示したいけどどうしよ ('A`)
    }

    void ILendView.NotifyBookEntityNotFound()
    {
        this._bookEntityNotFoundMessageLabel.Visible = true;
    }
}

でもこうすればいいだけの話だった

public sealed class LendController : Controller<ILendView>
{
    private IList<BookEntity> _lendBookEntities;

    public void AddBookEntity(string bookId, string localId)
    {
        BookEntity bookEntity = this._repository.GetBookEntityById(bookId, localId);
        if (bookEntity == null)
        {
            this.View.NotifyBookEntityNotFound();
            return;
        }
        this._lendBookEntities.Add(bookEntity);
        /* this.View.AdditionalDisplayBookEntityInfo(bookEntity); */
        this.View.DisplayBookEntityInfos(this._lendBookEntities.ToArray()); // ★
    }
}

public interface ILendView : IView
{
    /* void AdditionalDisplayBookEntityInfo(BookEntity bookEntity); */
    void DisplayBookEntityInfos(BookEntity[] bookEntities); // ★
    void NotifyBookEntityNotFound();
}

public class Lend : System.Web.UI.Page, ILendView
{
    private LendController _controller;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            SessionStateAdapter<LendController>.SetItem(new LendController(RepositoryFactory.CreateRepository()));
        }
        this._controller = SessionStateAdapter<LendController>.GetItem();
        this._controller.SetView(this);
    }

    protected void _bookEntityAddButton_Click(object sender, EventArgs e)
    {
        this._controller.AddBookEntity(this._bookIdTextBox.Text, this._bookLocalIdTextBox.Text);
    }

    /* void ILendView.AdditionalDisplayBookEntityInfo(BookEntity bookEntity) */
    void ILendView.DisplayBookEntityInfos(BookEntity[] bookEntities) // ★
    {
        this._bookEntityNotFoundMessageLabel.Visible = false;
        this._bookEntityGridView.DataSource = bookEntities; // ★
        this._bookEntityGridView.DataBind(); // ★
    }

    void ILendView.NotifyBookEntityNotFound()
    {
        this._bookEntityNotFoundMessageLabel.Visible = true;
    }
}

ポストバックのたびに DataBind メソッドを呼び出す必要があると思い込んでいたのも原因。