<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/c4f.Bill-Evjen-Reuters/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/c4f.Bill-Evjen-Reuters/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/c4f.Bill-Evjen-Reuters/Posts</link>
    <language>en</language>
    <pubDate>Thu, 23 May 2013 00:36:32 GMT</pubDate>
    <lastBuildDate>Thu, 23 May 2013 00:36:32 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>1</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Extending the Personal Web Site Starter Kit</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50">&nbsp;</td>
<td class=""><span class="entry_description">This article shows how to work with the foundation of the Personal Web Site Starter Kit and expand upon it for your own personal use. It is rather easy to start incorporating your own features into this simple-to-use
 starter kit.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Bill Evjen Reuters</div>
<div class="entry_company"><a href="http://blogs.msdn.com/controlpanel/blogs/"></a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Intermediate</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Less Than $50</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Studio Express Editions</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b>Lost
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p><b>Summary: </b>Learn how to extend the new Personal Web Site Starter Kit, which is an available project type in Visual Web Developer 2005 Express Edition. (21 printed pages)
</p>
<h4>Contents<br>
</h4>
<p><a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx#extendpws_topic1">Introduction</a><br>
<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx#extendpws_topic2">First, Personalize Your Site</a><br>
<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx#extendpws_topic3">Extending the Administration Abilities</a><br>
<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx#extendpws_topic4">Conclusion</a><br>
<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx#extendpws_topic6">Related Books</a><br>
<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx#extendpws_topic5">About the Author</a>
</p>
<h4><a></a>Introduction</h4>
<p>Inside Visual Studio 2005 and Visual Web Developer 2005 Express Edition, you will find an ASP.NET project type labeled as
<i>Personal Web Site Starter Kit</i>. This project type provides you with a basic Web site to modify as your own. I provide an overview of the starter kit in my article
<a href="http://msdn.microsoft.com/coding4fun/webcoder/extendpws/default.aspx?pull=/library/en-us/dnaspp/html/pws.asp">
Introducing the Personal Web Site Starter Kit</a>. If you need an introduction to the starter kit, then I recommend that you review this previous article first.
</p>
<p>The Personal Web Site Starter Kit includes a home page, a resume page, a page that allows you to list your favorite links, and a photo album. The main piece of the starter kit is focused on the photo album and the administrator pages built around this functionality,
 which allows you to upload, modify, and delete photos as well as entire albums. </p>
<p>The starter kit is a great example of how to use some of the new and exciting features provided by ASP.NET 2.0 in an application. This starter kit utilizes master pages (the ability to provide your application with a master template), new configuration capabilities,
 XML definitions of the site structure (<code>.sitemap</code> files), and more. </p>
<p>This article will take a look at how to extend some of these features, which is the explicit purpose of the starter kit. It is called a starter kit for a reason! You should consider this starter kit as a starting point to use and build a truly unique application
 for yourself. In the end, you might not even end up with what is referred to as a personal Web site; but instead, it might be something else entirely.
</p>
<h4><a></a>First, Personalize Your Site</h4>
<p>The first thing you will want to do is to go through the site and completely personalize the pages you are going to keep in the application. This means changes to the master page and any of the content pages contained within the application.
</p>
<p>Besides that, one important item you should be aware of for this application is that it doesn't take advantage of any sort of .NET caching capabilities. This means that each page is not stored in the system cache to reuse in order to save the cost of regenerating
 the page. </p>
<p>In most cases, you are most likely going to be presenting data on your personal Web site that isn't going to be changing frequently. Therefore, to get better performance from your application, you can specify that your ASP.NET pages should be cached for
 a specific period of time. </p>
<p>However, since this application makes use of the new capability of using master pages and content pages, there are now two pages that are combined when invoked to create a single ASP.NET page. Since this is the case, where exactly would you apply the caching?
</p>
<p>When using master pages, you would apply caching to the content page, not to the master page. When using the
<code>OutputCache</code> page directive, you need to place this in the content page for your page for any caching to occur. This is shown here:</p>
<pre></pre>
<pre class="csharpcode"><span class="asp">&lt;%@ OutputCache Duration=&quot;60&quot; VaryByParam=&quot;None&quot; %&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Placing this page directive in any of the content pages of your application will cause both the contents of the content page and the associated master page to be cached by the system (remember that it is a single page at this point) for 60 seconds.
</p>
<h4><a></a>Extending the Administration Abilities</h4>
<p>The rest of this article will look at extending various parts of the application by examining the administrator's abilities to remotely manage the content of the application.
</p>
<p>Presently, if you are logged in as an administrator for the application, you will have the ability to create, delete, or modify photo albums that are presented through the application. The rest of the application's content, mainly the textual content and
 the provided &quot;cool links,&quot; are just hard-coded text contained in the content pages themselves. We will take a look at placing some of these items in a SQL Express database as well as making this content remotely manageable through the browser, as are the photo
 albums. </p>
<h5>Adding a Page to the Application</h5>
<p>The first step that we will take is to add some additional pages to the overall application. Presently, when you log into the application as an administrator and click on the Manage link, you are brought to the
<code>Albums.aspx</code> page shown here in Figure 1. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig013.gif"><img src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig01_thumb1.gif"></a>
</p>
<p><b>Figure 1. Albums administration page</b> </p>
<p>As you can see, the main administration page allows you to create and manage photo albums as well the ability to add and modify the user database, which really is simply a link to the
<code>webadmin.axd</code> http handler (this will run only for the local user). </p>
<p>In order to add the ability for the site administrator to manage some site content from this page in addition to the photo albums presented, we are going to have to make some changes here. You could just add these new management capabilities to the page
 presented here in Figure 1, but instead of that, let's add a couple of additional management pages just to make it a little more interesting.
</p>
<p>For our example, let's cause the Manage link to go to a simple page that allows for further navigation to manage the photo albums, another page to manage users, and a third page to manage site content.
</p>
<p>To create these new pages, let's first make the necessary changes to the <code>
web.sitemap</code> file. The original <code>web.sitemap</code> file is presented in Listing 1.
</p>
<p><b>Listing 1: The original web.sitemap file</b></p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span> <span class="attr">encoding</span><span class="kwrd">=&quot;utf-8&quot;</span> ?<span class="kwrd">&gt;</span><br><span class="kwrd">&lt;</span><span class="html">siteMap</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Home&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Default.aspx&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Resume&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Resume.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Links&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Links.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Albums&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Albums.aspx&quot;</span> <span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Photos&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Photos.aspx&quot;</span> <span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Details&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Details.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>         <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Register&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Register.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Manage&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Albums.aspx&quot;</span> <span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Photos&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Photos.aspx&quot;</span> <span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Details&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Details.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>         <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">siteMap</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>A sitemap is an XML description of your application's structure. This definition is then used by various site navigation server controls that are made available to you. For instance, the Personal Web Site Starter Kit uses the
<code>Menu</code> server control at the top of the application in a horizontal view. This control simply reads the content of the
<code>web.sitemap</code> file through a <code>SiteMapDataSource</code> server control in order to generate its results. This menu is presented here in Figure 2.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig028.gif"><img height="52" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig02_thumb6.gif" width="404"></a>
</p>
<p><b>Figure 2. The new menu</b> </p>
<p>If you look at the original <code>.sitemap</code> file shown in Listing 1, you can see that the Manage link is defined to use the URL
<code>Admin/Albums.aspx</code>. For our example, let's change around the Admin section so that we can break out some of the management capabilities onto separate pages. In the end, you should have a
<code>web.sitemap</code> file as presented here in Listing 2. </p>
<p><b>Listing 2: The modified web.sitemap</b></p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">=&quot;1.0&quot;</span> <span class="attr">encoding</span><span class="kwrd">=&quot;utf-8&quot;</span> ?<span class="kwrd">&gt;</span><br><span class="kwrd">&lt;</span><span class="html">siteMap</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Home&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Default.aspx&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Resume&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Resume.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Links&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Links.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Albums&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Albums.aspx&quot;</span> <span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Photos&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Photos.aspx&quot;</span> <span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Details&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Details.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>         <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Register&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Register.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Manage&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Manage.aspx&quot;</span> <span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Albums&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Albums.aspx&quot;</span> <span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Photos&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Photos.aspx&quot;</span> <span class="kwrd">&gt;</span><br>               <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Details&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Details.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Site Content&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Content.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">siteMapNode</span> <span class="attr">title</span><span class="kwrd">=&quot;Manage Users&quot;</span> <span class="attr">url</span><span class="kwrd">=&quot;Admin/Users.aspx&quot;</span> <span class="kwrd">/&gt;</span><br>         <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">siteMapNode</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">siteMap</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>From this example, you can see that adding additional pages to the application's navigation system is simply a matter of adding some additional XML nodes to the
<code>web.sitemap</code> document. In this case, we changed the destination of the Manage link (it now points to
<code>Admin/Manage.aspx</code>) and we added two new pages: <code>Content.aspx</code> and
<code>Users.aspx</code>. Now let's look at creating some of these pages. </p>
<h6>Manage.aspx</h6>
<p>Let's create a new page for the Manage link in the navigation system: <code>Manage.aspx</code>. In creating
<code>Manage.aspx</code>, remember that we are going to want to create this ASP.NET page so that it is located in the Admin folder (as seen in the Visual Studio Solution Explorer). To do this, right-click the Admin folder in the Solution Explorer and select
<b>Add New Item</b>. This will pull up the <b>Add New Item</b> dialog box, which will allow you to select a new Web form. This is shown here in Figure 3.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig034.gif"><img height="303" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig03_thumb2.gif" width="450"></a>
</p>
<p><b>Figure 3. Adding a new content page</b> </p>
<p>In this dialog box, note that we are interested in creating a <i>content page</i>. A content page works with a master page and we have specified this by selecting the
<b>Select master page</b> check box. Doing this and clicking <b>Add</b> will pull up another dialog that allows you to select the master page to use for this particular content page. In this case, there is only one master page to choose from:
<code>Default.master</code>. </p>
<p>This content page —<code>Manage.aspx</code>— will simply contain three image buttons. The code for this page is presented here in Listing 3.
</p>
<p><b>Listing 3: Manage.aspx</b></p>
<pre></pre>
<pre class="csharpcode"><span class="asp">&lt;%@ Page Language=&quot;VB&quot; MasterPageFile=&quot;~/Default.master&quot; <br>    AutoEventWireup=&quot;false&quot; CodeFile=&quot;Manage.aspx.vb&quot; Inherits=&quot;Manage&quot; <br>    title=&quot;Manage Your Personal Web Site&quot; %&gt;</span><br><span class="kwrd">&lt;</span><span class="html">asp:Content</span> <span class="attr">ID</span><span class="kwrd">=&quot;Content1&quot;</span> <span class="attr">ContentPlaceHolderID</span><span class="kwrd">=&quot;Main&quot;</span> <span class="attr">Runat</span><span class="kwrd">=&quot;Server&quot;</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;shim column&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;page&quot;</span> <span class="attr">id</span><span class="kwrd">=&quot;admin-albums&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;sidebar&quot;</span><span class="kwrd">&gt;</span><br>          <span class="kwrd">&lt;</span><span class="html">h3</span><span class="kwrd">&gt;</span>Choose an area to manage<span class="kwrd">&lt;/</span><span class="html">h3</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;content&quot;</span><span class="kwrd">&gt;</span><br>          <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">width</span><span class="kwrd">=&quot;90%&quot;</span><span class="kwrd">&gt;&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span><br>             <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;&lt;</span><span class="html">asp:ImageButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;ImageButton1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>                  <span class="attr">ImageUrl</span><span class="kwrd">=&quot;../Images/button_sitecontent.gif&quot;</span> <br>                  <span class="attr">PostBackUrl</span><span class="kwrd">=&quot;Content.aspx&quot;</span> <span class="kwrd">/&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>             <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;&lt;</span><span class="html">asp:ImageButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;ImageButton2&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>                  <span class="attr">ImageUrl</span><span class="kwrd">=&quot;../Images/button_manageusers.gif&quot;</span>  <br>                  <span class="attr">PostBackUrl</span><span class="kwrd">=&quot;Users.aspx&quot;</span> <span class="kwrd">/&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>             <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;&lt;</span><span class="html">asp:ImageButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;ImageButton3&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>                  <span class="attr">ImageUrl</span><span class="kwrd">=&quot;../Images/button_albums.gif&quot;</span>  <br>                  <span class="attr">PostBackUrl</span><span class="kwrd">=&quot;Albums.aspx&quot;</span> <span class="kwrd">/&gt;&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>      <br>   <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:Content</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Since this is a content page, you can see that it points to the master page to use the
<code>@Page</code> directive's <code>MasterPageFile</code> attribute. Also, this page is rather simple. It uses the same CSS classes as the
<code>Albums.aspx</code> page found in the Admin folder and simply contains a table holding three image buttons that each point to a different administration page. Running this page in the browser produces the graphic shown here in Figure 4.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig043.gif"><img height="277" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig04_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 4. The new Administration home page</b> </p>
<p>Now that the <code>Manage.aspx</code> page is in place, the next step we will take is to create the
<code>Users.aspx</code> page. I explain how in the next section. </p>
<h6>Users.aspx</h6>
<p>This page will be rather simple to create. If you look back at Figure 1, you will notice that there is a small section on the page that is dedicated to allowing you to manage your users and the user's settings (shown in the lower left-hand corner of the
 page). Since we want to separate the administration functionality a bit, we will end up pulling this section from the
<code>Albums.aspx</code> page and then placing it in the <code>Users.aspx</code> page instead.
</p>
<p>The first step is to create the <code>Users.aspx</code> page. Just like the <code>
Manage.aspx</code> page, create the <code>Users.aspx</code> page inside of the Admin folder and make sure that it is a content page using the
<code>Default.master</code> page as its master template. </p>
<p>The code to use for <code>Users.aspx</code> is shown here in Listing 4. </p>
<p><b>Listing 4: Users.aspx</b></p>
<pre></pre>
<pre class="csharpcode"><span class="asp">&lt;%@ Page Language=&quot;VB&quot; MasterPageFile=&quot;~/Default.master&quot; <br>    AutoEventWireup=&quot;false&quot; CodeFile=&quot;Users.aspx.vb&quot; Inherits=&quot;Users&quot; <br>    title=&quot;Manage Users&quot; %&gt;</span><br><span class="kwrd">&lt;</span><span class="html">asp:Content</span> <span class="attr">ID</span><span class="kwrd">=&quot;Content1&quot;</span> <span class="attr">ContentPlaceHolderID</span><span class="kwrd">=&quot;Main&quot;</span> <span class="attr">Runat</span><span class="kwrd">=&quot;Server&quot;</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;shim column&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;page&quot;</span> <span class="attr">id</span><span class="kwrd">=&quot;admin-albums&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;sidebar&quot;</span><span class="kwrd">&gt;</span><br>          <span class="kwrd">&lt;</span><span class="html">h3</span><span class="kwrd">&gt;</span>Users and Settings<span class="kwrd">&lt;/</span><span class="html">h3</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;content&quot;</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;</span>To add or remove user accounts and change other site-wide <br>         settings, use the <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">=&quot;webadmin.axd&quot;</span><span class="kwrd">&gt;</span>ASP.NET Web Site <br>         Administration Tool<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>.<span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;</span>Note: If this site is being hosted on <span class="kwrd">&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Visual Web Developer <br>         Web Server<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;</span>, please<br>         access the <span class="kwrd">&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>ASP.NET Web Site Administration Tool<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;</span> via the <br>         <span class="kwrd">&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>ASP.NET Configuration<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;</span><br>         menu item within Visual Web Developer.<span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>      <br>   <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:Content</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This page is very much like the <code>Manage.aspx</code> page. It uses the same CSS styling and has some simple text and a link to the
<code>webadmin.axd</code> http handler. Again, it is important to note that you will be able to invoke this http handler only as a local user on the server.
</p>
<p>Figure 5 illustrates what is produced by the <code>Users.aspx</code> page. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig053.gif"><img height="277" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig05_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 5. The new User Administration page</b> </p>
<p>The next and final step is to create an administration page that will allow us to manage the content of the home page.
</p>
<h4>Building a Simple Content Management System</h4>
<p>If you look at the home page for the Personal Web Site Starter Kit, you will notice that much of the text it contains is hard-coded in the actual page. Though this works, let's look at changing this structure so that the content is retrieved from a SQL Server
 2005 Express database instead. We will also look at allowing the site administrator (someone under the Administrators role) to update this information directly from an admin page that we will later create (<code>Content.aspx</code>).
</p>
<p>The first step we will take to achieve this is to modify the SQL Express file,
<code>Personal.mdf</code>. We will use <code>Personal.mdf</code> to store the home page content in addition to the photo album information for which it is already used. It is important to note that this is just one example. You could also build this content
 management system to use an XML file instead of the SQL Express file. </p>
<h5>Modifying the Personal.mdf File</h5>
<p>From the Visual Web Developer Solution Explorer, expand the App_Data folder. You will notice that there are two SQL Server Express files in this folder,
<code>ASPNETDB.mdf</code> and <code>Personal.mdf</code>. </p>
<p><code>ASPNETDB.mdf</code> is used by ASP.NET to store values for the various systems that are part of ASP.NET such as the new membership and role management systems. All the application roles and the user's credentials are stored in this database file.
</p>
<p>The <code>Personal.mdf</code> file is used to store the photo album information and even the photos themselves (they are contained within the Photos table). Our first step is to add a new table to this database. This new table is where we will store the
 text that will appear on the home page of the Personal Web Site Starter Kit. </p>
<p>To create a new table in the SQL Server Express file, choose the Database Explorer tab in Visual Web Developer and expand the Data Connections root node. Expand the Tables folder for the
<code>Personal.mdf</code> database presented by expanding Personal.mdf, then Tables in the Database Explorer. You will see that this database contains two tables called Albums and Photos. To add an additional table, right-click the Tables folder and select
<b>Add New Table</b> from the list of options. </p>
<p>In this table, we are interested in adding a few simple columns. Following is a list of columns and their associated data types to add to the table:
</p>
<p>Column Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Data Type</p>
<pre>TextId                           int</pre>
<pre>Homepage_Welcome                 varchar(MAX)</pre>
<pre>Homepage_WhatsNew                varchar(MAX)</pre>
<pre>Homepage_WhatsUpLately&nbsp;        &nbsp; varchar(MAX)</pre>
<p>After these columns are in place, right-click the <code>TextId</code> column and set this column to be a primary key. Doing this will allow us to later update the other columns as the update will require a way to identify the row that needs updating (even
 though we are using just one row in the table). </p>
<p>In the end, your table definition should appear as shown in Figure 6. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig063.gif"><img height="150" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig06_thumb1.gif" width="416"></a>
</p>
<p><b>Figure 6. Table definition</b> </p>
<p>Next, save the table and you will then be presented with a dialog box that asks you to name the table. Name the table SiteContent. After the table is named and saved, it will then appear in the Database Explorer with the other two tables. Next, right-click
 the newly created table <code>SiteContent</code> and select <b>Show Table Data</b> from the list of options. This will show a list of columns plus the data contained within each (which will be just NULL values at this point).
</p>
<p>From here, you can enter in the content of your page, but since we will be building a page to do this later, let's just enter a numeric
<code>0</code> in the <code>TextId </code>column and the string &quot;<code>Test</code>&quot; in each of the other columns. This is illustrated here in Figure 7.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig073.gif"><img height="60" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig07_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 7. Adding content to the new table</b> </p>
<p>Now that the <code>Personal.mdf</code> file contains the additional table that will drive the home page of the application, let's next re-code the home page to work from this database table.
</p>
<h6>Re-coding the Default.aspx page to work from the Personal.mdf file</h6>
<p>Pull up the <code>Default.aspx</code> page in Visual Studio and scroll to the bottom of the page. Here at the bottom is an
<code>ObjectDataSource</code> control. This control drives the photo that appears on the sidebar of the page. ASP.NET 2.0 provides a number of new data controls that work to pull data from different data sources as well as perform operations such as inserting,
 deleting, and updating data in these data stores. Looking in the Toolbox of Visual Studio, you will notice that in addition to the
<code>ObjectDataSource</code> control used in the Personal Web Site Starter Kit, there are also data source controls for working with SQL databases, Microsoft Access, XML sources, and sitemaps. The
<code>ObjectDataSource</code> control used on the <code>Default.aspx</code> page is shown here:</p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:ObjectDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;ObjectDataSource1&quot;</span> <span class="attr">Runat</span><span class="kwrd">=&quot;server&quot;</span>  <br> <span class="attr">TypeName</span><span class="kwrd">=&quot;PhotoManager&quot;</span> <span class="attr">SelectMethod</span><span class="kwrd">=&quot;GetPhotos&quot;</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:ObjectDataSource</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>You would use the <code>ObjectDataSource</code> control when you are interested in using a traditional three-tiered model when it comes to working with data that is presented on your page. From this example, you can see that the photos are retrieved through
 the class <code>PhotoManager</code> (specified by the <code>TypeName</code> attribute) using the
<code>GetPhotos</code> method (specified by the <code>SelectMethod</code> attribute). You will find the
<code>PhotoManager.vb</code> or <code>.cs</code> class file in the App_Code folder of your project. Contained within this class, you will then find the
<code>GetPhotos</code> method : </p>
<p><b>Visual C#</b></p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> List&lt;Photo&gt; GetPhotos()<br>{<br>        <span class="kwrd">return</span> GetPhotos(GetRandomAlbumID());<br>}<br></pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p><b>Visual Basic</b></p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Shared</span> <span class="kwrd">Function</span> GetPhotos() <span class="kwrd">As</span> Generic.List(Of Photo)<br>        <span class="kwrd">Return</span> GetPhotos(GetRandomAlbumID())<br><span class="kwrd">End</span> Function</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>In changing the <code>Default.aspx</code> page so that it will now display textual content as retrieved from the
<code>Personal.mdf</code> file, you could certainly add another class to the App_Code folder that deals with getting this information and then use another
<code>ObjectDataSource</code> control to invoke a <code>Select</code> method in that class. Constructing the site content retrieval in this manner will allow you to extend the data model that the application is already using. However, for the sake of learning,
 let's instead look at using a <code>SqlDataSource</code> control to pull the site content data.
</p>
<h6>Setting up the SqlDataSource control</h6>
<p>To set up a <code>SqlDataSource</code> control that will be used to pull the site content data from the
<code>Personal.mdf</code> file, open up the <code>Default.aspx</code> page in Visual Studio in the Design mode (the Design tab is at the bottom of the document window). Once the page is open in the Design mode, drag a
<code>SqlDataSource</code> control onto the design surface so that it is positioned next to the
<code>ObjectDataSource</code> control at the bottom of the page. Highlighting the
<code>SqlDataSource</code> control and clicking the green arrow that will appear will allow you to open the control's smart tag. From here, you will then be able to click on the Configure Data Source link. This will launch a wizard that will allow you to configure
 the <code>SqlDataSource</code> control to get at the site content data found in the
<code>Personal.mdf</code> file. The first page of this wizard is shown in Figure 8.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig083.gif"><img height="349" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig08_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 8. Configuring a Data Source Wizard</b> </p>
<p>As the wizard asks you to configure the <code>SqlDataSource</code> control, you can see that you first need to establish a connection to the
<code>Personal.mdf</code> file. Since there is already a defined connection in the
<code>web.config</code> file, you will see the option of <b>Personal</b> in the drop-down list. Select
<b>Personal</b> and then click the <b>Next</b> button. </p>
<p>The next screen in the wizard allows you to specify the table you want to work with. In this case, select
<code>SiteContent</code> from the drop-down list. Since we want to deal with everything contained in this table, select the asterisk (<code>*</code>), a wildcard character that indicates that you are interested in everything this table offers. This is shown
 here in Figure 9. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig095.gif"><img height="349" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig09_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 9. Configuring a Data Source: Selecting the table</b> </p>
<p>You are now ready to move onto the next screen in the wizard, which allows you to test the connection to the
<code>Personal.mdf</code> database you just created. Clicking the <b>Test Query</b> button should produce the results illustrated here in Figure 10.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig103.gif"><img height="349" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig10_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 10. Configuring a Data Source: Previewing the Data</b> </p>
<p>When you are done, click <b>Finish</b>. Listing 5 shows the code of the <code>
SqlDataSource</code> control that Visual Studio will generate from the instructions provided to the wizard.
</p>
<p><b>Listing 5: The SqlDataSource control code as generated by Visual Studio</b></p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br> <span class="attr">ConnectionString</span><span class="kwrd">=&quot;&lt;%$ ConnectionStrings:Personal %&gt;&quot;</span><br> <span class="attr">SelectCommand</span><span class="kwrd">=&quot;SELECT * FROM [SiteContent]&quot;</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Now that the <code>SqlDataSource</code> control is in place, let's move on to the next step of modifying the
<code>Default.aspx</code> page to show the content that will come from this datasource control.
</p>
<h6>Modifying the Default.aspx page to show the content coming from the SqlDataSource control</h6>
<p>Looking at the source code for the <code>Default.aspx</code> page, you will notice that the page is a content page that uses the only master page available to it in the application:
<code>Default.master</code>. This master page exposes a single area for the content page to use. This area is then defined in the content page through the use of a single Content server control located on the page. Inside of the Content server control, you
 will see that the content page is divided up into a few distinct sections, all of which are defined by
<code>&lt;div&gt;</code> elements. A framework of this is shown here in Listing 6. </p>
<p><b>Listing 6: Looking at the structure of the Default.aspx page</b></p>
<pre></pre>
<pre class="csharpcode"><span class="asp">&lt;%@   Page Language=&quot;VB&quot; MasterPageFile=&quot;~/Default.master&quot; <br>      Title=&quot;Your Name Here | Home&quot;<br>      CodeFile=&quot;Default.aspx.vb&quot; Inherits=&quot;Default_aspx&quot; %&gt;</span><br><span class="kwrd">&lt;</span><span class="html">asp:content</span> <span class="attr">id</span><span class="kwrd">=&quot;Content1&quot;</span> <span class="attr">contentplaceholderid</span><span class="kwrd">=&quot;Main&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;shim column&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>   <br>   <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">class</span><span class="kwrd">=&quot;page&quot;</span> <span class="attr">id</span><span class="kwrd">=&quot;home&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;sidebar&quot;</span><span class="kwrd">&gt;</span><br>         <span class="rem">&lt;!-- Content removed for clarity --&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;content&quot;</span><span class="kwrd">&gt;</span><br>         <span class="rem">&lt;!-- Content removed for clarity --&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:content</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>From this code framework, you can see that the actual page is divided up into two sections: the sidebar content (defined using
<code>&lt;div id=&quot;sidebar&quot;&gt;</code>) and the main part of the page (using <code>&lt;div id=&quot;content&quot;&gt;</code>). Since we are interested in driving the content contained in the
<code>&lt;div id=&quot;content&quot;&gt;</code> section of the page, let's focus on that part of the page. To accomplish this, we are going to place a
<code>DataList</code> server control in this section of the page and pull out the values we need using
<code>Eval</code> statements. This is illustrated in Listing 7. </p>
<p><b>Listing 7: Using a DataList control to drive the content on the page</b></p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;content&quot;</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">asp:DataList</span> <span class="attr">ID</span><span class="kwrd">=&quot;DataList1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>    <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">h3</span><span class="kwrd">&gt;</span>Welcome   to My Site<span class="kwrd">&lt;/</span><span class="html">h3</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;</span><span class="asp">&lt;%</span># Eval(<span class="str">&quot;Homepage_Welcome&quot;</span>)<span class="asp">%&gt;</span><span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">hr</span>   <span class="kwrd">/&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;whatsnew&quot;</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">h4</span><span class="kwrd">&gt;</span>What's New<span class="kwrd">&lt;/</span><span class="html">h4</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;</span><span class="asp">&lt;%</span># Eval(<span class="str">&quot;Homepage_WhatsNew&quot;</span>) <span class="asp">%&gt;</span><span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&quot;coollinks&quot;</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">h4</span><span class="kwrd">&gt;</span>Cool Links<span class="kwrd">&lt;/</span><span class="html">h4</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">ul</span> <span class="attr">class</span><span class="kwrd">=&quot;link&quot;</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;&lt;</span><span class="html">a</span> <span class="attr">HREF</span><span class="kwrd">=&quot;#&quot;</span> <span class="attr">TARGET</span><span class="kwrd">=&quot;_self&quot;</span><span class="kwrd">&gt;</span>Lorem ipsum dolositionr<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;&lt;</span><span class="html">a</span> <span class="attr">HREF</span><span class="kwrd">=&quot;#&quot;</span> <span class="attr">TARGET</span><span class="kwrd">=&quot;_self&quot;</span><span class="kwrd">&gt;</span>Lorem ipsum dolositionr<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;&lt;</span><span class="html">a</span> <span class="attr">HREF</span><span class="kwrd">=&quot;#&quot;</span> <span class="attr">TARGET</span><span class="kwrd">=&quot;_self&quot;</span><span class="kwrd">&gt;</span>Lorem ipsum dolositionr<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;&lt;</span><span class="html">a</span> <span class="attr">HREF</span><span class="kwrd">=&quot;#&quot;</span> <span class="attr">TARGET</span><span class="kwrd">=&quot;_self&quot;</span><span class="kwrd">&gt;</span>Lorem ipsum dolositionr<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;&lt;</span><span class="html">a</span> <span class="attr">HREF</span><span class="kwrd">=&quot;#&quot;</span> <span class="attr">TARGET</span><span class="kwrd">=&quot;_self&quot;</span><span class="kwrd">&gt;</span>Lorem ipsum dolositionr<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;/</span><span class="html">ul</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">hr</span> <span class="kwrd">/&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">h4</span><span class="kwrd">&gt;</span>What's Up Lately <span class="kwrd">&lt;/</span><span class="html">h4</span><span class="kwrd">&gt;</span><br>         <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;</span><span class="asp">&lt;%</span># Eval(<span class="str">&quot;Homepage_WhatsUpLately&quot;</span>) <span class="asp">%&gt;</span><span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">asp:DataList</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>From the example illustrated here in Listing 7, you can see that the <code>DataList</code> server control binds itself to the
<code>SqlDataSource1</code> control by using the <code>DataSourceId</code> attribute.</p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:DataList</span> <span class="attr">ID</span><span class="kwrd">=&quot;DataList1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:DataList</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The <code>DataList</code> control provides a number of template types that can be used for display purposes. Examples include a header template, footer template, item template, separator template, and more. Since we are interested in displaying a single
 row from the SiteContent table, we therefore need to employ only the <code>&lt;ItemTemplate&gt;
</code>node and nothing more. When the <code>DataList</code> control is then rendered, it will display the contents of the
<code>&lt;ItemTemplate&gt;</code> section once for each row contained in the table in which it is bound.
</p>
<p>Inside the <code>&lt;ItemTemplate&gt;</code> section, we can then get at the contents for a particular column of the SiteContent table through the use of a data-binding expression Eval. In ASP.NET 2.0, the data binding has been simplified and can now be as simple
 as:</p>
<pre><code></code></pre>
<pre class="csharpcode"><span class="asp">&lt;%</span># Eval(<span class="str">&quot;Homepage_Welcome&quot;</span>) <span class="asp">%&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>This statement will cause the contents contained in the table column Homepage_Welcome to be displayed in its place.
</p>
<p>Save the Default.aspx page and run it in the browser. You should now see the results as shown in Figure 11.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig113.gif"><img height="325" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig11_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 11. The new dynamic home page</b> </p>
<h6>Creating an administrator page to update the page content</h6>
<p>Our final step is to create a page for the Site Content link of the <code>Manage.aspx</code> page. This new page will allow administrators to update the content that appears on the
<code>Default.aspx</code> page. For this step, create a new content page called <code>
Content.aspx</code> that uses the <code>Default.master</code> page as a template.
</p>
<p>This page will require you to place a <code>SqlDataSource</code> control on it. The configuration of this
<code>SqlDataSource</code> control will be a bit different than that of the <code>
Default.aspx</code> page. Since we are going to be also dealing with the updating of the data on this administration page, we are therefore interested in having this
<code>SqlDataSource</code> control perform the proper updates to the data contained in the SiteContent table. Therefore, as you work through the SqlDataSource control's configuration wizard, when you are working from the Select statement page of the wizard,
 click the <b>Advanced</b> button in the dialog box and select the first check box to build a
<code>SqlDataSource</code> control that will allow for the updating of the data. These dialogs are shown here in Figure 12.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig123.gif"><img height="314" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig12_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 12. Automatically generating SQL statements</b> </p>
<p>After working through the wizard, your <code>SqlDataSource</code> control should appear as shown in Listing 8.
</p>
<p><b>Listing 8: The SqlDataSource control code as generated by Visual Studio</b></p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>  <span class="attr">ConnectionString</span><span class="kwrd">=&quot;&lt;%$ ConnectionStrings:Personal %&gt;&quot;</span><br><span class="attr">DeleteCommand</span><span class="kwrd">=&quot;DELETE FROM [SiteContent] WHERE [TextId] = <br>   @original_TextId&quot;</span> <br><span class="attr">InsertCommand</span><span class="kwrd">=&quot;INSERT INTO [SiteContent] ([TextId], <br>   [Homepage_Welcome], [Homepage_WhatsNew], [Homepage_WhatsUpLately]) <br>   VALUES (@TextId, @Homepage_Welcome, @Homepage_WhatsNew, <br>   @Homepage_WhatsUpLately)&quot;</span><br><span class="attr">SelectCommand</span><span class="kwrd">=&quot;SELECT * FROM [SiteContent]&quot;</span> <br><span class="attr">UpdateCommand</span><span class="kwrd">=&quot;UPDATE [SiteContent] SET [Homepage_Welcome] = <br>   @Homepage_Welcome, [Homepage_WhatsNew] = @Homepage_WhatsNew, <br>   [Homepage_WhatsUpLately] = @Homepage_WhatsUpLately WHERE [TextId] = <br>   @original_TextId&quot;</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">DeleteParameters</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;original_TextId&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;Int32&quot;</span> <span class="kwrd">/&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">DeleteParameters</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">UpdateParameters</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;Homepage_Welcome&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;Homepage_WhatsNew&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;Homepage_WhatsUpLately&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;original_TextId&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;Int32&quot;</span> <span class="kwrd">/&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">UpdateParameters</span><span class="kwrd">&gt;</span><br>        <span class="kwrd">&lt;</span><span class="html">InsertParameters</span><span class="kwrd">&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;TextId&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;Int32&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;Homepage_Welcome&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;Homepage_WhatsNew&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span><br>            <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;Homepage_WhatsUpLately&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span><br>        <span class="kwrd">&lt;/</span><span class="html">InsertParameters</span><span class="kwrd">&gt;</span><br>    <span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Of course, we are interested only in reading (using the <code>Select</code> statement) and updating (using the
<code>Update</code> statement) the data in the SiteContent table. Since we are not interested in deleting or inserting new rows of data into the SiteContent table, you can feel free to delete the
<code>UpdateCommand</code> and <code>InsertCommand</code> attributes and their values from the
<code>SqlDataSource</code> control. You can also feel free to delete the <code>&lt;DeleteParameters&gt;</code> and the
<code>&lt;InsertParameters&gt;</code> sections as well. </p>
<p>Now that the <code>SqlDataSource</code> control is in place, let's add a <code>
FormView</code> control to the page to drive all the displaying and updating of the content to the SiteContent table. Drag and drop a
<code>FormView</code> control onto the <code>Content.aspx</code> page. </p>
<p>From the smart tab of the <code>FormView</code> control, select the <code>SqlDataSource1</code> control instance as the data source to use. Then, moving back to the source code view of the
<code>Content.aspx</code> page, you can see that a lot of code has been added to the
<code>FormView</code> control. Since we are interested in updating only a single row of content and we are not interesting in deleting the row of data from the SiteContent table or adding any new rows to the table, you should then delete the
<code>&lt;InsertItemTemplate&gt;</code> section. Also, in the <code>&lt;ItemTemplate&gt;</code> section, delete the
<code>LinkButtons</code> for deleting and adding new content. The only <code>LinkButton</code> control in the
<code>&lt;ItemTemplate&gt;</code> section should be for editing the content displayed. After a little styling and deleting the above-mentioned sections, your
<code>FormView</code> control should appear similar to that illustrated in Listing 9.
</p>
<p><b>Listing 9: The FormView control (after modifications)</b></p>
<pre></pre>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:FormView</span> <span class="attr">ID</span><span class="kwrd">=&quot;FormView1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">DataKeyNames</span><span class="kwrd">=&quot;TextId&quot;</span> <br> <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span> <span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">EditItemTemplate</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>TextId:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span><span class="kwrd">=&quot;TextIdLabel1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Eval(&quot;TextId&quot;) %&gt;'</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Homepage_Welcome:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:TextBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;Homepage_WelcomeTextBox&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Bind(&quot;Homepage_Welcome&quot;) %&gt;'</span> <span class="attr">TextMode</span><span class="kwrd">=&quot;MultiLine&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:TextBox</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Homepage_WhatsNew:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:TextBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;Homepage_WhatsNewTextBox&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Bind(&quot;Homepage_WhatsNew&quot;) %&gt;'</span> <span class="attr">TextMode</span><span class="kwrd">=&quot;MultiLine&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:TextBox</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Homepage_WhatsUpLately:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:TextBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;Homepage_WhatsUpLatelyTextBox&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Bind(&quot;Homepage_WhatsUpLately&quot;) %&gt;'</span> <span class="attr">TextMode</span><span class="kwrd">=&quot;MultiLine&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:TextBox</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;UpdateButton&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">CausesValidation</span><span class="kwrd">=&quot;True&quot;</span> <span class="attr">CommandName</span><span class="kwrd">=&quot;Update&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Update&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;UpdateCancelButton&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span> <span class="attr">CommandName</span><span class="kwrd">=&quot;Cancel&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Cancel&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">EditItemTemplate</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>TextId:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span><span class="kwrd">=&quot;TextIdLabel&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Eval(&quot;TextId&quot;) %&gt;'</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Homepage_Welcome:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span><span class="kwrd">=&quot;Homepage_WelcomeLabel&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Bind(&quot;Homepage_Welcome&quot;) %&gt;'</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Homepage_WhatsNew:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span><span class="kwrd">=&quot;Homepage_WhatsNewLabel&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Bind(&quot;Homepage_WhatsNew&quot;) %&gt;'</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">p</span><span class="kwrd">&gt;&lt;</span><span class="html">b</span><span class="kwrd">&gt;</span>Homepage_WhatsUpLately:<span class="kwrd">&lt;/</span><span class="html">b</span><span class="kwrd">&gt;&lt;</span><span class="html">br</span> <span class="kwrd">/&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span><span class="kwrd">=&quot;Homepage_WhatsUpLatelyLabel&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">Text</span><span class="kwrd">='&lt;%# Bind(&quot;Homepage_WhatsUpLately&quot;) %&gt;'</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;EditButton&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <br>      <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span> <span class="attr">CommandName</span><span class="kwrd">=&quot;Edit&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Edit&quot;</span><span class="kwrd">&gt;</span><br>      <span class="kwrd">&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span><br>   <span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span><br><span class="kwrd">&lt;/</span><span class="html">asp:FormView</span><span class="kwrd">&gt;</span>
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>From this code listing, you can see that we added a few break lines and changed the edit template so that instead of using standard
<code>TextBox</code> controls, we are now using multilined textboxes. </p>
<p>Running these pages as an administrator will produce the results shown in Figure 13.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig133.gif"><img height="289" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig13_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 13. The edit content page</b> </p>
<p>Clicking the <b>Edit</b> button will allow you to edit the contents of each of these sections. This is illustrated in Figure 14.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig143.gif"><img height="289" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/942789/extendpws_fig14_thumb1.gif" width="450"></a>
</p>
<p><b>Figure 14. Changing the home page content</b> </p>
<p>Now the information placed inside of these controls will be updated into the SiteContent table, which in turn will be output to the
<code>Default.aspx</code> page. Now the content of the <code>Default.aspx</code> page is remotely manageable.
</p>
<h4><a></a>Conclusion</h4>
<p>This article showed you how to work with the foundation of the Personal Web Site Starter Kit and expand upon it for your own personal use. As you can see, it is rather easy to start incorporating your own features into this simple-to-use starter kit.
</p>
<p>Have fun and happy coding! </p>
<h4><a></a>Related Books</h4>
<ul>
<li><b>Bill Evjen,</b> <a href="http://shopping.msn.com/search/detail.aspx?pcId=12175&amp;prodId=2184857&amp;ptnrid=141&amp;ptnrdata=0">
ASP.NET 2.0 Beta Preview</a></li></ul>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Bill-Evjen-Reuters/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:a7340959842c49cb85ed9e7600d959b6">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Extending-the-Personal-Web-Site-Starter-Kit</comments>
      <itunes:summary>



&amp;nbsp;
This article shows how to work with the foundation of the Personal Web Site Starter Kit and expand upon it for your own personal use. It is rather easy to start incorporating your own features into this simple-to-use
 starter kit.



Bill Evjen Reuters


Difficulty: Intermediate
Time Required: 
1-3 hours
Cost: Less Than $50
Software: Visual Studio Express Editions
Hardware: 
Download: Lost








Summary: Learn how to extend the new Personal Web Site Starter Kit, which is an available project type in Visual Web Developer 2005 Express Edition. (21 printed pages)
 
Contents

Introduction
First, Personalize Your Site
Extending the Administration Abilities
Conclusion
Related Books
About the Author
 
Introduction
Inside Visual Studio 2005 and Visual Web Developer 2005 Express Edition, you will find an ASP.NET project type labeled as
Personal Web Site Starter Kit. This project type provides you with a basic Web site to modify as your own. I provide an overview of the starter kit in my article

Introducing the Personal Web Site Starter Kit. If you need an introduction to the starter kit, then I recommend that you review this previous article first.
 
The Personal Web Site Starter Kit includes a home page, a resume page, a page that allows you to list your favorite links, and a photo album. The main piece of the starter kit is focused on the photo album and the administrator pages built around this functionality,
 which allows you to upload, modify, and delete photos as well as entire albums.  
The starter kit is a great example of how to use some of the new and exciting features provided by ASP.NET 2.0 in an application. This starter kit utilizes master pages (the ability to provide your application with a master template), new configuration capabilities,
 XML definitions of the site structure (.sitemap files), and more.  
This article will take a look at how to extend some of these features, which is the explicit purpose of the starter kit. It is called a star</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Extending-the-Personal-Web-Site-Starter-Kit</link>
      <pubDate>Fri, 03 Nov 2006 11:45:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Extending-the-Personal-Web-Site-Starter-Kit</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/942789_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/942789_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Bill Evjen Reuters</dc:creator>
      <itunes:author>Bill Evjen Reuters</itunes:author>
      <slash:comments>8</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Extending-the-Personal-Web-Site-Starter-Kit/RSS</wfw:commentRss>
      <category>Web</category>
      <category>starter kit</category>
    </item>    
</channel>
</rss>