Creating the Home Page for a Simple Storefront with LINQ (Page 1 of 4 )
In the last article, we laid out the plans for a simple storefront for the Adventure Works Cycles sample database. We briefly examined the database structure, and created a master page to unify the look of our new web site. We also created a page that would display the appropriate image given a ProductID through the query string. In this article, we'll continue with the construction of the storefront.
Creating the Home Page
Let's create the store's home page. On this page will be a short welcome messages, a link to the product browse page, and then a short list of the latest products. We'll tackle the basic structure of the page first, and then we can move on to the meat of the page: using LINQ with ASP.NET. Create a Default.aspx page. Be sure to set its master page to MasterPage.master, which we created in the last article. The page will be created with a simple Content control. Here's the page without the latest items part:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Title="Adventure Works Cycles" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content"
Runat="Server">
<p>Welcome to Adventure Works Cycles, your source for cycles and cycling accessories.</p>
<p><a href="Browse.aspx">Browse Products</a></p>
<p>Check out some of our latest items:</p>
</asp:Content>
Now we need a control that will display the latest items for us. Let's go with a ListView control, which is relatively new and easy to work with:
<asp:ListView ID="LatestItemsView" runat="server">
</asp:ListView>
Before the ListView becomes operational, we need to provide it with a few templates. First is the LayoutTemplate, which defines the “master layout,” if you will, of the ListView. Place this inside of the ListView tags:
<LayoutTemplate>
<p>Here are some of our latest items:</p>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
Notice how we provide a PlaceHolder control here. It's a placeholder for the list of items, and it's a necessary part of LayoutTemplate. It also must have the name “itemPlaceholder” in order to work.
Next: ItemTemplate >>
More .NET Articles
More By Peyton McCullough