Click here to Skip to main content
15,881,938 members
Articles / Web Development / ASP.NET

Presentation Model in Action

Rate me:
Please Sign up or sign in to vote.
4.93/5 (31 votes)
3 Feb 2008CPOL14 min read 124.4K   1.6K   119  
Use the Presentation Model pattern in ASP.NET Web site, Windows Forms and WPF
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomerList.ascx.cs" Inherits="CustomerList" %>
<h4>
    Customer List</h4>
<asp:GridView ID="CustomerListGridView" runat="server" AutoGenerateColumns="False"
    Width="100%" BorderWidth="0px" CellPadding="2" CellSpacing="1" 
    DataSourceID="CustomerListDataSource"  DataKeyNames="Id"
    OnSelectedIndexChanged="CustomerListGridView_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="CustomerPresentationModel" SelectMethod="GetCustomerList"
    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 Code Project Open License (CPOL)


Written By
Architect
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions