Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Presentation Model and Dependency Injection

, 26 Apr 2009
ASP.NET MVVM provides a framework to implement the Presentation Model pattern, a.k.a. the Model-View-ViewModel pattern in ASP.NET projects. Developers can take advantages of Dependency Injection and Event Broker to write concise, elegant and business focused code.
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Demo.WebApp.CustomerList" Codebehind="CustomerList.ascx.cs" %>
<h4>
    Customer List</h4>
<asp:GridView ID="CustomerGridView" runat="server" AutoGenerateColumns="False"
    Width="100%" BorderWidth="0px" CellPadding="2" CellSpacing="1" 
    DataSourceID="CustomerListDataSource"  DataKeyNames="Id"
    OnSelectedIndexChanged="CustomerGridView_SelectedIndexChanged">
    <AlternatingRowStyle CssClass="Grid-Item-Alternate" />
    <RowStyle CssClass="Grid-Item" />
    <HeaderStyle CssClass="Grid-Header" />
    <SelectedRowStyle CssClass="Grid-Item-Selected" />
    <Columns>
        <asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Id">
            <ItemTemplate>
                <asp:LinkButton ID="btnSelect" Text='<%# Eval("Name")%>' runat="server" CommandName="Select" Visible="<%# !UsePopup %>"/>
                <asp:Hyperlink runat="server" NavigateUrl='<%# "javascript:var win=window.open(\"CustomerDetails.aspx?id=" + Eval("Id") + "\");" %>'
                               Text='<%# Eval("Name")%>'
                               Visible="<%# UsePopup %>"
                />
            </ItemTemplate>
        </asp:TemplateField>

        <asp:BoundField HeaderStyle-HorizontalAlign="Left" HeaderText="Address" DataField="Address"/>
        
    </Columns>
</asp:GridView>
<asp:ObjectDataSource ID="CustomerListDataSource" runat="server" DataObjectTypeName="Demo.DataModel.Customer"
    TypeName="Demo.WebApp.ICustomerList" SelectMethod="SelectCustomerList"
    OnObjectCreating="CustomerListDataSource_ObjectCreating" />

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Yiyi Sun
Architect
Canada Canada
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 26 Apr 2009
Article Copyright 2009 by Yiyi Sun
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid