熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET MVC 4框架揭秘:MVP(3)[2]

2022-06-13   來源: .NET編程 

  <Columns>

  <asp:BoundField DataField=Name HeaderText=姓名 />

  <asp:BoundField DataField=Gender HeaderText=性別 />

  <asp:BoundField DataField=BirthDate

  HeaderText=出生日期

  DataFormatString={:dd/MM/yyyy} />

  <asp:BoundField DataField=Department HeaderText=部門/>

  </Columns>

  </asp:GridView>

  </div>

  </form>

  </body>

  </html>

  如下所示的是該Web頁面的後台代碼的定義它實現了定義在IEmployeeSearchView接口的兩個方法(BindEmployees和BindDepartments)和一個事件(DepartmentSelected)表示Presenter的同名只讀屬性在構造函數中被初始化在頁面加載的時候(Page_Load方法)Presenter的Initialize方法被調用而在查詢按鈕被點擊的時候(ButtonSearch_Click)事件DepartmentSelected被觸發

  public partial class Default : Page IEmployeeSearchView

  {

  public EmployeeSearchPresenter Presenter { get; private set; }

  public event EventHandler<DepartmentSelectedEventArgs> DepartmentSelected;

  public Default()

  {

  thisPresenter = new EmployeeSearchPresenter(this)

  }

  protected void Page_Load(object sender EventArgs e)

  {

  if (!thisIsPostBack)

  {

  thisPresenterInitialize()

  }

  }

  protected void ButtonSearch_Click(object sender EventArgs e)

  {

  string department = thisDropDownListDepartmentsSelectedValue;

  DepartmentSelectedEventArgs eventArgs =

  new DepartmentSelectedEventArgs(department)

  if (null != DepartmentSelected)

  {

  DepartmentSelected(this eventArgs)

  }

  }

  public void BindEmployees(IEnumerable<Employee> employees)

  {

  thisGridViewEmployeesDataSource = employees;

  thisGridViewEmployeesDataBind()

  }

  public void BindDepartments(IEnumerable<string> departments)

  {

  thisDropDownListDepartmentsDataSource = departments;

  thisDropDownListDepartmentsDataBind()

  }

  }

       返回目錄ASPNET MVC 框架揭秘

       編輯推薦

       Java程序性能優化讓你的Java程序更快更穩定

       Visual C++音頻/視頻技術開發與實戰

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/16125.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.