asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

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


发布日期:2022年04月17日
 
ASP.NET MVC 4框架揭秘:MVP(3)[2]

<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++音频/视频技术开发与实战

[] []

               

上一篇:ASP.NET MVC 4框架揭秘:MVP(2)[1]

下一篇:ASP.NET MVC 4框架揭秘:MVP(3)[1]