Click here to Skip to main content
15,896,348 members
Articles / General Programming / Architecture

Binding Web Pages with nHydrate

,
Rate me:
Please Sign up or sign in to vote.
4.71/5 (5 votes)
1 Jun 2011Ms-PL12 min read 21K   256   14  
Bind your UI controls to generated objects generically
<%@ Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="false" CodeBehind="CountryList.aspx.cs" Inherits="Acme.EFExample.Website.CountryList" EnableViewState="false" %>
<%@ Register src="~/UserControls/PagingControl.ascx" tagname="PagingControl" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<h2>Country List</h2>
<p>
This is a list of countries. To add a new one, click the 'New Item' link at the bottom of the page. You can edit and remove items from this list as well.
The 'Delete' link will use Javascript to prompt you for confirmation of deletion and use a web service to perform the delete asynchronously.
JQuery is then used to remove the row from the table smoothly.
Notice that the mark-up for this page has only a grid and a paging control.
Also notice that the code behind is very small too. Most of the work is being performed by the base page and the binding class that can be used for any screen.
</p>
<p>
<strong>*NOTE</strong>: Keep in mind that you can not remove objects that are dependencies of other objects. 
The delete web method will check if the specified object is being used and not remove it if it is.
You cannot delete a country that has been associated with a customer object.
</p>

<uc1:PagingControl ID="PagingControl1" runat="server" />
<asp:GridView ID="grdItem" runat="server" 
AutoGenerateColumns="false" 
GridLines="None"
CssClass="grid"
HeaderStyle-CssClass="gridheader"
AlternatingRowStyle-CssClass="gridaltrow"
EmptyDataText="There are currently no items to display"
EmptyDataRowStyle-CssClass="emptygrid">

<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="CreatedDate" HeaderText="Created" ItemStyle-Wrap="false" DataFormatString="{0:yyyy-MMM-dd}" />
<asp:BoundField DataField="ModifiedDate" HeaderText="Modified" ItemStyle-Wrap="false" DataFormatString="{0:yyyy-MMM-dd}" />

<asp:TemplateField ItemStyle-Width="100" ItemStyle-HorizontalAlign="Right">
<ItemTemplate>
<asp:HyperLink ID="linkEdit" runat="server" Text="Edit" />
<asp:HyperLink ID="linkDelete" runat="server" Text="Delete" NavigateUrl="#" />
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>

<div class="buttonblock">
<a href="/countryedit.aspx">New Item</a>
</div>

</asp:Content>

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)



Written By
Software Developer (Senior) Hewlett Packard
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions