<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PeterKellner.net &#187; ObjectDataSource</title>
	<atom:link href="http://peterkellner.net/category/net-20/objectdatasource/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focused, JavaScript,HTML5 (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 11 May 2012 16:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>With ASP.NET WebForms, How to Keep / Stop a Data Control Like GridView From Retrieving Data</title>
		<link>http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data</link>
		<comments>http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 21:35:00 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[WebForms]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/</guid>
		<description><![CDATA[The What and Where
Something that may not be obvious is if are creating an asp.net WebForms project and you put a datasource such as SqlDataSource or ObjectDataSource for example on the page, how can you prevent the SqlSelect associated with that datasource from being triggered.
The answer is to set the control’s visible property to false.&#160; [...]]]></description>
			<content:encoded><![CDATA[<h2>The What and Where</h2>
<p>Something that may not be obvious is if are creating an asp.net <a href="http://msdn.microsoft.com/en-us/library/ms973868.aspx">WebForms</a> project and you put a datasource such as <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.aspx">SqlDataSource</a> or <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx">ObjectDataSource</a> for example on the page, how can you prevent the SqlSelect associated with that datasource from being triggered.</p>
<p>The answer is to set the control’s visible property to false.&#160; That’s it!</p>
<p>  <span id="more-1529"></span>
<p>&#160;</p>
<h2>The Why</h2>
<p>The reason you might want to do this is for a case where you have a public facing web page that might be easily subjected to a denial of service attach.&#160; If that web page is always causing some SqlDataSource to fire, you could easily find your <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> overloaded.&#160; At least by checking to see a user is logged in before firing the sql statement, you buy yourself a little bit of protection.</p>
<p>&#160;</p>
<h2>The Code</h2>
<pre class="csharpcode"><span class="asp">&lt;%@ Page Language=&quot;C#&quot; %&gt;</span>

<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span class="kwrd">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>

    <span class="kwrd">protected</span> <span class="kwrd">void</span>
        GridView1_SelectedIndexChanged(<span class="kwrd">object</span> sender, EventArgs e)
    {

    }

    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Init(<span class="kwrd">object</span> sender, EventArgs e)
    {
        <span class="kwrd">if</span> (!Context.User.Identity.IsAuthenticated)
        {
            GridView1.Visible = <span class="kwrd">false</span>;
        }
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">=&quot;form1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
        <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>
            <span class="attr">ConnectionString</span><span class="kwrd">=&quot;&lt;%$ ConnectionStrings:CodeCampSV06 %&gt;&quot;</span>
            <span class="attr">SelectCommand</span>=
            <span class="kwrd">&quot;SELECT [Id], [Username], [Email] FROM [Attendees] ORDER BY [Id] DESC&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span><span class="kwrd">=&quot;GridView1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoGenerateColumns</span><span class="kwrd">=&quot;False&quot;</span>
            <span class="attr">DataKeyNames</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span>
            <span class="attr">onselectedindexchanged</span><span class="kwrd">=&quot;GridView1_SelectedIndexChanged&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">InsertVisible</span><span class="kwrd">=&quot;False&quot;</span>
                    <span class="attr">ReadOnly</span><span class="kwrd">=&quot;True&quot;</span> <span class="attr">SortExpression</span><span class="kwrd">=&quot;Id&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Username&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Username&quot;</span>
                    <span class="attr">SortExpression</span><span class="kwrd">=&quot;Username&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Email&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Email&quot;</span>
                <span class="attr">SortExpression</span><span class="kwrd">=&quot;Email&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:GridView</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a List of Recent Posts To The Silicon Valley Code Camp Home Page (From RSS Feed)</title>
		<link>http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet</link>
		<comments>http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 21:44:26 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Repeater]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/</guid>
		<description><![CDATA[There are 10,000 ways to do this.&#160; Back way back when (ASP.NET 1.1) days, we would have created either a custom control to do this, then added a Repeater control on the page to display it.&#160; Well, the Silicon Valley Code Camp Website was started back in those days and since what I want is [...]]]></description>
			<content:encoded><![CDATA[<p>There are 10,000 ways to do this.&#160; Back way back when (<a href="http://www.asp.net/">ASP.NET</a> 1.1) days, we would have created either a custom control to do this, then added a Repeater control on the page to display it.&#160; Well, the <a href="http://siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> Website was started back in those days and since what I want is so simple, I decided to do just that (minus the custom control).&#160; I really only wanted to spend about 10 minutes doing this, and as it turned out, it took about 30.&#160; Oh well, 3x plan verses execution.&#160; Could do better next time.</p>
<p>So, here is basically what I want on the left side bar of the home page of Silicon Valley Code Camp:</p>
<p> <span id="more-1366"></span>
<p><a href="http://blog.siliconvalley-codecamp.com/"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="RSS Feed Look" border="0" alt="RSS Feed Look" src="http://peterkellner.net/FilesForWebDownload/AddingaListofRecentPostsToTheSiliconVall_CF44/image.png" width="177" height="346" /></a> </p>
<p>&#160;</p>
<p>First, I’ll attach my simple project I build to do this standalone so you can run it yourself, then, I’ll do a quick step through of the key code.&#160; </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:a42e11ac-159d-4bc9-8e14-637ad835e07b" class="wlWriterEditableSmartContent">
<div><a href="http://peterkellner.net/FilesForWebDownload/AddingaListofRecentPostsToTheSiliconVall_CF44/SimpleRSSReaderJustTitleAndLink.zip" target="_self">SimpleRSSReaderJustTitleAndLink.zip</a></div>
</p>
</div>
<p>All that is really in this project is a simple c# class file that contains a business object and one get method to retrieve the list.&#160; That file is called RSSFeed.cs.&#160; I’ve pasted all the code of that class below:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> System.Collections.Generic;<span style="color: #0000ff">using</span> System.ComponentModel;<span style="color: #0000ff">using</span> System.Linq;<span style="color: #0000ff">using</span> System.Xml.Linq;

<span style="color: #0000ff">namespace</span> App_Code{    [DataObject(<span style="color: #0000ff">true</span>)]    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RSSFeedObject    {

        [DataObjectMethod(DataObjectMethodType.Select, <span style="color: #0000ff">true</span>)]        <span style="color: #0000ff">public</span> List&lt;RSSItem&gt; Get(<span style="color: #0000ff">int</span> numberToGet)        {            XDocument feedXML = XDocument.Load              (<span style="color: #006080">&quot;http://blog.siliconvalley-codecamp.com/feed/&quot;</span>);

            var feeds = feedXML.Descendants(<span style="color: #006080">&quot;item&quot;</span>).                Select(feed =&gt; <span style="color: #0000ff">new</span>                   {                       PostTitle = feed.Element(<span style="color: #006080">&quot;title&quot;</span>).Value,                       PostURL = feed.Element(<span style="color: #006080">&quot;link&quot;</span>).Value                   });            var rssItems = <span style="color: #0000ff">new</span> List&lt;RSSItem&gt;();            <span style="color: #0000ff">int</span> id = 0;            <span style="color: #0000ff">foreach</span> (var rec <span style="color: #0000ff">in</span> feeds)            {                rssItems.Add(<span style="color: #0000ff">new</span> RSSItem                                (id,rec.PostTitle,rec.PostURL));                id++;                <span style="color: #0000ff">if</span> (id &gt;= numberToGet)                {                    <span style="color: #0000ff">break</span>;                }            }            <span style="color: #0000ff">return</span> rssItems;                            }

    }

    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> RSSItem    {        [DataObjectField(<span style="color: #0000ff">true</span>)]        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Id { get; set; }

        [DataObjectField(<span style="color: #0000ff">false</span>)]        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> PostTitle { get; set; }

        [DataObjectField(<span style="color: #0000ff">false</span>)]        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> PostURL { get; set; }

        <span style="color: #0000ff">public</span> RSSItem(<span style="color: #0000ff">int</span> id, <span style="color: #0000ff">string</span> postTitle,                        <span style="color: #0000ff">string</span> postURL)        {            Id = id;            PostTitle = postTitle;            PostURL = postURL;        }    }}</pre>
<p></div>
<p>Then, in the Default.aspx page, you can simply reference this object with a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx">Repeater</a> and an <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx">ObjectDataSource</a> and you are done!&#160; That is it, very simple.&#160; Below is the page code.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:ObjectDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;ObjectDataSourceRSS&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span>   <span style="color: #ff0000">SelectMethod</span><span style="color: #0000ff">=&quot;Get&quot;</span> <span style="color: #ff0000">TypeName</span><span style="color: #0000ff">=&quot;App_Code.RSSFeedObject&quot;</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">SelectParameters</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">DefaultValue</span><span style="color: #0000ff">=&quot;5&quot;</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">=&quot;numberToGet&quot;</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">=&quot;Int32&quot;</span> <span style="color: #0000ff">/&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">SelectParameters</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:ObjectDataSource</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:Repeater</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;RepeaterRSS&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">=&quot;ObjectDataSourceRSS&quot;</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">FooterTemplate</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">FooterTemplate</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>           <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:HyperLink</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;HyperLinkURL&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span>                <span style="color: #ff0000">NavigateUrl</span><span style="color: #0000ff">='&lt;%# Eval(&quot;PostURL&quot;) %&gt;'</span>               <span style="color: #ff0000">Text</span><span style="color: #0000ff">='&lt;%# Eval(&quot;PostTitle&quot;) %&gt;'</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:HyperLink</span><span style="color: #0000ff">&gt;</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:Repeater</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>I’m sure someone is going to point out how this could have been done in three lines of code.&#160; Until then, I’ll keep this in the Silicon Valley Code Camp site.</p>
<p>BTW, if the site looks different, it’s because a wizard html/css guy has come by and cleaned it up to look good. What you see in the top screen shot is what it looks like without any formatting.&#160; Just unordered list and listitems with no formatting.</p>
<p>HTH’s!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/09/12/simplerssreader-in-silicon-valley-code-camp-objectdatasource-repeater-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExtJS Meetup Tonight in San Francisco, Sample URLs of Running Code Here</title>
		<link>http://peterkellner.net/2009/05/14/extjs-meetup-aspnet-code-samples/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extjs-meetup-aspnet-code-samples</link>
		<comments>http://peterkellner.net/2009/05/14/extjs-meetup-aspnet-code-samples/#comments</comments>
		<pubDate>Thu, 14 May 2009 14:47:59 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Speaking]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/05/14/extjs-meetup-aspnet-code-samples/</guid>
		<description><![CDATA[ At tonight&#8217;s meet up, we will be having several short presentations on the new features in ExtJS version 3.0.&#160; For my short presentation, I will be showing how to build a simple asp.net application that lets you Create, Update, Delete and Edit Membership data using the ASP.NET built in membership providers.&#160; I will be [...]]]></description>
			<content:encoded><![CDATA[<p> At tonight&#8217;s meet up, we will be having several short presentations on the new features in <a href="http://extjs.com">ExtJS</a> version 3.0.&#160; For my short presentation, I will be showing how to build a simple asp.net application that lets you Create, Update, Delete and Edit Membership data using the ASP.NET built in membership providers.&#160; I will be leverage code from an MSDN article I wrote a while back here along with the URL to the meetup location.</p>
<p><a title="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/calendar/10302891/" href="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/calendar/10302891/">http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/calendar/10302891/</a></p>
<p><a title="http://msdn.microsoft.com/en-us/library/aa478947.aspx" href="http://msdn.microsoft.com/en-us/library/aa478947.aspx">http://msdn.microsoft.com/en-us/library/aa478947.aspx</a></p>
<p>My plan is to do a progression where I start with a trivial GridPanel, then work myself in 5 steps to a full working membership editor that looks like this:</p>
<p> <span id="more-308"></span>
<p><a href="http://peterkellner.net/FilesForWebDownload/ExtJSMeetupTonightinSanFranciscoHereisas_6DA2/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/ExtJSMeetupTonightinSanFranciscoHereisas_6DA2/image_thumb.png" width="392" height="425" /></a></p>
<p>&#160;</p>
<p>If you want to to run the code I will be explaining tonight, here are some links:</p>
<p><a title="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorASimpleGrid.html" href="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorASimpleGrid.html">http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorASimpleGrid.html</a></p>
<p><a title="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorBMoreGrid.html" href="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorBMoreGrid.html">http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorBMoreGrid.html</a></p>
<p><a title="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorCMoreGridWithPaging.html" href="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorCMoreGridWithPaging.html">http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorCMoreGridWithPaging.html</a></p>
<p><a title="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorDMoreGridEditing.html" href="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorDMoreGridEditing.html">http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorDMoreGridEditing.html</a></p>
<p><a title="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorEAddDeleteToolbar.html" href="http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorEAddDeleteToolbar.html">http://aspnetextjsdemo.peterkellner.net/ExtJSProfileEditorEAddDeleteToolbar.html</a></p>
<p>If you want a more complete demonstration of ExtJS in general along with more details of the code, I’m presenting a full length version of this at he Bay.Net Meeting in Microsoft next Wednesday evening.&#160; Here are the full details.&#160; These events are both community events are free.</p>
<p><a title="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&amp;mid=49" href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&amp;mid=49">http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=378&amp;mid=49</a></p>
<p>Hope to see you at one of the events!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/05/14/extjs-meetup-aspnet-code-samples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Retrieve a GridView Based on a CheckBoxList of Items with Asp.Net using ObjectDataSource with a little LINQ Thrown In</title>
		<link>http://peterkellner.net/2008/12/07/checkboxlist-gridview-aspnet-howto-mutiple-selections/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=checkboxlist-gridview-aspnet-howto-mutiple-selections</link>
		<comments>http://peterkellner.net/2008/12/07/checkboxlist-gridview-aspnet-howto-mutiple-selections/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 06:08:02 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=210</guid>
		<description><![CDATA[So, the problem is you have a list that you want to retrieve from that contains multiple values.&#160; Say for example, you have a list of 5 cities and you want to retrieve a list of people in some combination of those cities.&#160; If you use the class SelectValue method with GridView you run out [...]]]></description>
			<content:encoded><![CDATA[<p>So, the problem is you have a list that you want to retrieve from that contains multiple values.&#160; Say for example, you have a list of 5 cities and you want to retrieve a list of people in some combination of those cities.&#160; If you use the class SelectValue method with <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx">GridView</a> you run out of steam because it&#8217;s only one value.&#160; What you&#8217;d really like to do is pass the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxlist.aspx">CheckBoxList</a> into the GridView as a selection parameter, but unfortunately, when you do that, you just get the one selected value from the CheckBoxList, not all the values.</p>
<p>I&#8217;m sure you can make a custom <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx">ControlParameter</a> in <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx">ObjectDataSource</a> to solve this, but I really don&#8217;t have time for that.&#160; I just wanted something quick (which I now have and thought I&#8217;d share).</p>
<p> <span id="more-210"></span>
<p>Basically, what I did was create an invisible label on my GridView that will get the string of values I want to retrieve, then, my ObjectDataSource gets one value (the string) and parses it into small values.&#160; My plan is to do a quick run through of the code here, but then also post the project so you can see for yourself how it works.</p>
<p>Here we go.</p>
<p>First, let&#8217;s make a simple BusinessObject class that returns to us some data.&#160; The basic object that will be returned is the Person defined as follows:</p>
<div class="csharpcode">
<pre class="alt"> <span class="kwrd">public</span> <span class="kwrd">class</span> Person</pre>
<pre>    {</pre>
<pre class="alt">        <span class="kwrd">public</span> Person()</pre>
<pre>        {</pre>
<pre class="alt">        }</pre>
<pre>&#160;</pre>
<pre class="alt">        <span class="kwrd">public</span> Person(<span class="kwrd">string</span> _name, <span class="kwrd">int</span> _id)</pre>
<pre>        {</pre>
<pre class="alt">            <span class="kwrd">this</span>._name = _name;</pre>
<pre>            <span class="kwrd">this</span>._id = _id;</pre>
<pre class="alt">        }</pre>
<pre>&#160;</pre>
<pre class="alt">        <span class="kwrd">private</span> <span class="kwrd">string</span> _name;</pre>
<pre>        <span class="kwrd">private</span> <span class="kwrd">int</span> _id;</pre>
<pre class="alt">&#160;</pre>
<pre>        <span class="kwrd">public</span> <span class="kwrd">string</span> name</pre>
<pre class="alt">        {</pre>
<pre>            get { <span class="kwrd">return</span> _name; }</pre>
<pre class="alt">            set { _name = <span class="kwrd">value</span>; }</pre>
<pre>        }</pre>
<pre class="alt">&#160;</pre>
<pre>        <span class="kwrd">public</span> <span class="kwrd">int</span> id</pre>
<pre class="alt">        {</pre>
<pre>            get { <span class="kwrd">return</span> _id; }</pre>
<pre class="alt">            set { _id = <span class="kwrd">value</span>; }</pre>
<pre>        }</pre>
<pre class="alt">    }</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { 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; } --></p>
<p>Next, we need two methods, the first is the method that does the heavy lifting (that is, takes a list of integers and returns the final list of people who have those cities in them, then, we need the method that polymorphically calls (did I spell that wrong, live writer thinks so&#8230; sorry) that method whose input is a single string.&#160; That method parses the string (which was assembled in page_load of the calling page) and calls the first one.</p>
<p>So, here is the method ObjectDataSource actually calls to get it&#8217;s view of the data (remember, ObjectDataSource only returns one view).</p>
<div class="csharpcode">
<pre class="alt"> <span class="kwrd">public</span> List&lt;Person&gt; GetPeopleByCityList(List&lt;<span class="kwrd">int</span>&gt; cityList)</pre>
<pre>        {</pre>
<pre class="alt">            List&lt;Person&gt; personList = <span class="kwrd">new</span> List&lt;Person&gt;</pre>
<pre>                                          {</pre>
<pre class="alt">                                              <span class="kwrd">new</span> Person(<span class="str">&quot;Peter_SanJose&quot;</span>, 1),</pre>
<pre>                                              <span class="kwrd">new</span> Person(<span class="str">&quot;Tom_Hartsdale&quot;</span>, 2),</pre>
<pre class="alt">                                              <span class="kwrd">new</span> Person(<span class="str">&quot;Eric_Chicago&quot;</span>, 3),</pre>
<pre>                                              <span class="kwrd">new</span> Person(<span class="str">&quot;Ron_SanJose&quot;</span>, 1),</pre>
<pre class="alt">                                              <span class="kwrd">new</span> Person(<span class="str">&quot;John_Chicago&quot;</span>, 3),</pre>
<pre>                                              <span class="kwrd">new</span> Person(<span class="str">&quot;Charly_Scarsdale&quot;</span>, 4)</pre>
<pre class="alt">                                          };</pre>
<pre>&#160;</pre>
<pre class="alt">            var personResult = from p <span class="kwrd">in</span> personList</pre>
<pre>                               <span class="kwrd">where</span> cityList.Contains(p.id)</pre>
<pre class="alt">                               orderby p.name</pre>
<pre>                               select p;</pre>
<pre class="alt">&#160;</pre>
<pre>            <span class="kwrd">return</span> personResult.ToList();</pre>
<pre class="alt">        }</pre>
<pre>&#160;</pre>
<pre class="alt">        <span class="kwrd">public</span> List&lt;Person&gt; GetPeopleByCityListString(<span class="kwrd">string</span> cityListString)</pre>
<pre>        {</pre>
<pre class="alt">            <span class="kwrd">if</span> (!String.IsNullOrEmpty(cityListString))</pre>
<pre>            {</pre>
<pre class="alt">                var values = cityListString.Split(<span class="str">';'</span>);</pre>
<pre>                var cityList = <span class="kwrd">new</span> List&lt;<span class="kwrd">int</span>&gt;();</pre>
<pre class="alt">                <span class="kwrd">foreach</span> (<span class="kwrd">string</span> s <span class="kwrd">in</span> values)</pre>
<pre>                {</pre>
<pre class="alt">                    cityList.Add(Convert.ToInt32(s));</pre>
<pre>                }</pre>
<pre class="alt">&#160;</pre>
<pre>                <span class="kwrd">return</span> GetPeopleByCityList(cityList);</pre>
<pre class="alt">            }</pre>
<pre>            <span class="kwrd">return</span> <span class="kwrd">null</span>;</pre>
<pre class="alt">        }</pre>
<pre>&#160;</pre>
<pre class="alt">    }</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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, the method that actually does the work.&#160; Notice I&#8217;m using the C# 3.0 object initializer syntax to build it, but normally, you&#8217;d be calling a database or something like that here.&#160; Also notice the clever <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx">LINQ</a> that does the equivalent of an SQL IN clause.&#160; That is, we&#8217;d normally be doing something like &quot;Select .. From Person Where CityId IN (1,3..)).&#160; It seems a little backwards to me, but it does the job.</p>
<p>So, now we have the business object, let&#8217;s put it to work.&#160; Let&#8217;s build a simple aspx page that has a CheckBoxList, GridView,Label and a Button.&#160; I&#8217;ll pre-populate the CheckBoxList just to keep my example simple.&#160; Normally, you&#8217;d be getting that data from another data source like a database.</p>
<p>So, Here is the aspx file we built.</p>
<div class="csharpcode">
<pre class="alt">&lt;%@ Page Language=<span class="str">&quot;C#&quot;</span> AutoEventWireup=<span class="str">&quot;true&quot;</span> CodeFile=<span class="str">&quot;Default.aspx.cs&quot;</span> Inherits=<span class="str">&quot;_Default&quot;</span> %&gt;</pre>
<pre>&lt;html xmlns=<span class="str">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</pre>
<pre class="alt">&lt;head runat=<span class="str">&quot;server&quot;</span>&gt;</pre>
<pre>    &lt;title&gt;&lt;/title&gt;</pre>
<pre class="alt">&lt;/head&gt;</pre>
<pre>&lt;body bgcolor=<span class="str">&quot;#00ccff&quot;</span>&gt;</pre>
<pre class="alt">    &lt;form id=<span class="str">&quot;form1&quot;</span> runat=<span class="str">&quot;server&quot;</span>&gt;</pre>
<pre>    &lt;div&gt;</pre>
<pre class="alt">        &lt;asp:Button ID=<span class="str">&quot;ButtonSearch&quot;</span> runat=<span class="str">&quot;server&quot;</span> Text=<span class="str">&quot;Retrieve&quot;</span> </pre>
<pre>            onclick=<span class="str">&quot;ButtonSearch_Click&quot;</span> /&gt;</pre>
<pre class="alt">        &lt;asp:Label ID=<span class="str">&quot;Label1&quot;</span> runat=<span class="str">&quot;server&quot;</span> Visible=<span class="str">&quot;false&quot;</span> Text=<span class="str">&quot;Label&quot;</span>&gt;&lt;/asp:Label&gt;</pre>
<pre>        &lt;asp:CheckBoxList ID=<span class="str">&quot;CheckBoxList1&quot;</span> runat=<span class="str">&quot;server&quot;</span>&gt;</pre>
<pre class="alt">            &lt;asp:ListItem Value=<span class="str">&quot;2&quot;</span>&gt;Hartsdale&lt;/asp:ListItem&gt;</pre>
<pre>            &lt;asp:ListItem Value=<span class="str">&quot;4&quot;</span>&gt;Scarsdale&lt;/asp:ListItem&gt;</pre>
<pre class="alt">            &lt;asp:ListItem Value=<span class="str">&quot;3&quot;</span>&gt;Chicago&lt;/asp:ListItem&gt;</pre>
<pre>            &lt;asp:ListItem Value=<span class="str">&quot;1&quot;</span>&gt;San Jose&lt;/asp:ListItem&gt;</pre>
<pre class="alt">        &lt;/asp:CheckBoxList&gt;</pre>
<pre>        &lt;asp:ObjectDataSource ID=<span class="str">&quot;ObjectDataSource1&quot;</span> runat=<span class="str">&quot;server&quot;</span> SelectMethod=<span class="str">&quot;GetPeopleByCityListString&quot;</span></pre>
<pre class="alt">            TypeName=<span class="str">&quot;BO.BusinessObject&quot;</span>&gt;</pre>
<pre>            &lt;SelectParameters&gt;</pre>
<pre class="alt">                &lt;asp:ControlParameter ControlID=<span class="str">&quot;Label1&quot;</span> Name=<span class="str">&quot;cityListString&quot;</span> PropertyName=<span class="str">&quot;Text&quot;</span></pre>
<pre>                    Type=<span class="str">&quot;String&quot;</span> /&gt;</pre>
<pre class="alt">            &lt;/SelectParameters&gt;</pre>
<pre>        &lt;/asp:ObjectDataSource&gt;</pre>
<pre class="alt">        &lt;asp:GridView ID=<span class="str">&quot;GridView1&quot;</span> runat=<span class="str">&quot;server&quot;</span> AutoGenerateColumns=<span class="str">&quot;False&quot;</span> </pre>
<pre>            DataSourceID=<span class="str">&quot;ObjectDataSource1&quot;</span>&gt;</pre>
<pre class="alt">            &lt;Columns&gt;</pre>
<pre>                &lt;asp:BoundField DataField=<span class="str">&quot;name&quot;</span> HeaderText=<span class="str">&quot;name&quot;</span> SortExpression=<span class="str">&quot;name&quot;</span> /&gt;</pre>
<pre class="alt">                &lt;asp:BoundField DataField=<span class="str">&quot;id&quot;</span> HeaderText=<span class="str">&quot;id&quot;</span> SortExpression=<span class="str">&quot;id&quot;</span> /&gt;</pre>
<pre>            &lt;/Columns&gt;</pre>
<pre class="alt">        &lt;/asp:GridView&gt;</pre>
<pre>    &lt;/div&gt;</pre>
<pre class="alt">    &lt;/form&gt;</pre>
<pre>&lt;/body&gt;</pre>
<pre class="alt">&lt;/html&gt;</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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>Notice that the asp controlparameter is passing the Label1 contents to the ObjectDataSource.&#160; To load that, we need to put some code in the Page_Load event that will set that line.&#160; Here is that code.&#160; It simply reads the checkboxlist and builds the string of numbers (3,5,7,9.).</p>
<p>I&#8217;m pretty sure that is it.&#160; Now, when you run the web site, you&#8217;ll get a screen that you can click multiple checkboxes on and get all the results that correspond with that checkbox.&#160; Here is what it should look like:</p>
<p><a href="http://peterkellner.net/blogimages/How.NetusingObjectDataSourcewithalittleL_13393/image_thumb1.png"><img border="0" alt="image_thumb1" src="http://peterkellner.net/blogimages/How.NetusingObjectDataSourcewithalittleL_13393/image_thumb1_thumb.png" width="166" height="244" /></a></p>
<p>Hope this Helps!&#160; And, if you it the better way by making a custom ControlParameter, post it here and we can all ignore this article.&#160; <img alt="Smile" src="http://messenger.msn.com/MMM2006-04-19_17.00/Resource/emoticons/regular_smile.gif" /></p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:cce21702-3bbb-4f92-b1fd-70d9beb3879d" class="wlWriterSmartContent">
<p>The Code <a href="http://peterkellner.net/blogimages/TEST_1370C/GridViewCheckBoxListExample1.zip" target="_blank">GridViewCheckBoxListExample1.zip</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/12/07/checkboxlist-gridview-aspnet-howto-mutiple-selections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Assigning a Custom Label Value in a ASP.NET GridView Using ObjectDataSource</title>
		<link>http://peterkellner.net/2008/08/06/assign-label-in-aspdotnet-to-gridview-in-objectdatasource/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=assign-label-in-aspdotnet-to-gridview-in-objectdatasource</link>
		<comments>http://peterkellner.net/2008/08/06/assign-label-in-aspdotnet-to-gridview-in-objectdatasource/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 14:10:07 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/08/06/assign-label-in-aspdotnet-to-gridview-in-objectdatasource/</guid>
		<description><![CDATA[In my previous post, Assigning a DropDownList Value in a ASP.NET GridView Using ObjectDataSource, I discussed how to put a DropDownList value in a GridView.&#160; As I explained, my motivation was to answer a common question that appears on often on the forums.&#160; If you are wondering what my process is for deciding what to [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, <a href="http://peterkellner.net/2008/08/05/assign-dropdownlist-in-aspdotnet-to-gridview-in-objectdatasource/">Assigning a DropDownList Value in a ASP.NET GridView Using ObjectDataSource</a>, I discussed how to put a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.80).aspx">DropDownList</a> value in a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(VS.80).aspx">GridView</a>.&#160; As I explained, my motivation was to answer a common question that appears on often on the forums.&#160; If you are wondering what my process is for deciding what to answer, there really is no process besides I see yet another question on the forum about this, and rather than answer it again, I write a post explaining it, then point my answer to the question at the post.&#160; This is what I did yesterday and below is the response to this <a href="http://forums.asp.net/p/1300497/2540027.aspx#2540027">forum post</a>.</p>
<p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/08/x2.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="x" src="http://peterkellner.net/wp/wp-content/uploads/2008/08/x-thumb2.png" width="540" height="208" /></a></p>
<p> <span id="more-129"></span>
<p>So, I have to say one of my main motivations for doing posts is I enjoy helping others through problems.&#160; It gives me a certain satisfaction to know that I have knowledge others may not at any give time and I have a great way to share that knowledge.&#160; It also makes me feel good when others go out of their way to appreciate the effort.&#160; I know when I post questions on forums and get good answers how happy I am, it&#8217;s good to know others appreciate my efforts.</p>
<p>So, continuing down that path, Here is the code necessary to answer Zimbran&#8217;s last question.</p>
<p> <!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }</style>
<div class="csharpcode">
<pre class="alt"><span class="asp">&lt;%@ Page Language=&quot;C#&quot; %&gt;</span></pre>
<pre><span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> </pre>
<pre class="alt"><span class="kwrd">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>ODS DDL Example<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">=&quot;form1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">        <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> </pre>
<pre>            <span class="attr">SelectMethod</span><span class="kwrd">=&quot;GetMembers&quot;</span></pre>
<pre class="alt">            <span class="attr">TypeName</span><span class="kwrd">=&quot;BusinessObject&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:ObjectDataSource</span><span class="kwrd">&gt;</span></pre>
<pre>        <span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span><span class="kwrd">=&quot;GridView1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoGenerateColumns</span><span class="kwrd">=&quot;False&quot;</span> </pre>
<pre class="alt">               <span class="attr">DataKeyNames</span><span class="kwrd">=&quot;Id&quot;</span></pre>
<pre>            <span class="attr">DataSourceID</span><span class="kwrd">=&quot;ObjectDataSource1&quot;</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">            <span class="kwrd">&lt;</span><span class="html">Columns</span><span class="kwrd">&gt;</span></pre>
<pre>                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">ReadOnly</span><span class="kwrd">=&quot;True&quot;</span> </pre>
<pre class="alt">                   <span class="attr">SortExpression</span><span class="kwrd">=&quot;Id&quot;</span> <span class="kwrd">/&gt;</span></pre>
<pre>                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Name&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Name&quot;</span> <span class="attr">SortExpression</span><span class="kwrd">=&quot;Name&quot;</span> <span class="kwrd">/&gt;</span></pre>
<pre class="alt">                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Email&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Email&quot;</span> <span class="attr">SortExpression</span><span class="kwrd">=&quot;Email&quot;</span> <span class="kwrd">/&gt;</span></pre>
<pre>                <span class="kwrd">&lt;</span><span class="html">asp:TemplateField</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Approved&quot;</span> <span class="attr">SortExpression</span><span class="kwrd">=&quot;Approved&quot;</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">                    <span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span></pre>
<pre>                        <span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span><span class="kwrd">=&quot;LabelYesOrNo&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> </pre>
<pre class="alt">                           <span class="attr">Text</span><span class="kwrd">='&lt;%# (bool) Eval(&quot;Approved&quot;) ? &quot;Yes&quot; : &quot;No&quot;  %&gt;'</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;</span></pre>
<pre>                    <span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">                <span class="kwrd">&lt;/</span><span class="html">asp:TemplateField</span><span class="kwrd">&gt;</span></pre>
<pre>            <span class="kwrd">&lt;/</span><span class="html">Columns</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">asp:GridView</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/08/06/assign-label-in-aspdotnet-to-gridview-in-objectdatasource/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Assigning a DropDownList Value in a ASP.NET GridView Using ObjectDataSource</title>
		<link>http://peterkellner.net/2008/08/05/assign-dropdownlist-in-aspdotnet-to-gridview-in-objectdatasource/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=assign-dropdownlist-in-aspdotnet-to-gridview-in-objectdatasource</link>
		<comments>http://peterkellner.net/2008/08/05/assign-dropdownlist-in-aspdotnet-to-gridview-in-objectdatasource/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 23:57:14 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/08/05/assign-dropdownlist-in-aspdotnet-to-gridview-in-objectdatasource/</guid>
		<description><![CDATA[As a moderator in the asp.net forums, I often see the same or similar questions.&#160; The answer to this question is pretty straight forward but not 100% obvious so I thought I&#8217;d do a post about in the hopes that with a couple key words, people will find the answer.&#160; The title basically says it [...]]]></description>
			<content:encoded><![CDATA[<p>As a moderator in the <a href="http://forums.asp.net/">asp.net forums</a>, I often see the same or similar questions.&nbsp; The answer to this question is pretty straight forward but not 100% obvious so I thought I&#8217;d do a post about in the hopes that with a couple key words, people will find the answer.&nbsp; The title basically says it all.&nbsp; We have a GridView that has a data column of type bool.&nbsp; We want to display in the GridView Yes or No depending on whether the data value is true or false.&nbsp; The example I&#8217;m showing does not help with making this an editable field (maybe a theme for another post if this one is popular) but simply shows yes or no.</p>
<p>The solution involves first dropping a <a href="http://msdn.microsoft.com/en-us/library/aa479339.aspx">GridView</a> and ObjectDataSource onto your design surface in Visual Studio.&nbsp; Then, using the little chevron on the GridView, choose edit columns and convert the column you are interested in making a <a href="http://www.w3schools.com/aspnet/control_dropdownlist.asp">DropDownList</a> into a template.&nbsp; From there replace the <a href="http://msdn.microsoft.com/en-us/library/aa479353.aspx">ItemTemplate</a> with the DropDownList code below.&nbsp; You get the code below.</p>
<p>&nbsp;</p>
<div class="csharpcode">
<pre class="alt"><span class="asp">&lt;%@ Page Language="C#" %&gt;</span></pre>
<pre>&nbsp;</pre>
<pre class="alt"><span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> </pre>
<pre><span class="kwrd">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">&nbsp;</pre>
<pre><span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">&nbsp;</pre>
<pre><span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">&nbsp;</pre>
<pre><span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>ODS DDL Example<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">asp:ObjectDataSource</span> <span class="attr">ID</span><span class="kwrd">="ObjectDataSource1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">SelectMethod</span><span class="kwrd">="GetMembers"</span></pre>
<pre>            <span class="attr">TypeName</span><span class="kwrd">="BusinessObject"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:ObjectDataSource</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span><span class="kwrd">="GridView1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">AutoGenerateColumns</span><span class="kwrd">="False"</span> <span class="attr">DataKeyNames</span><span class="kwrd">="Id"</span></pre>
<pre>            <span class="attr">DataSourceID</span><span class="kwrd">="ObjectDataSource1"</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">            <span class="kwrd">&lt;</span><span class="html">Columns</span><span class="kwrd">&gt;</span></pre>
<pre>                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">="Id"</span> <span class="attr">HeaderText</span><span class="kwrd">="Id"</span> <span class="attr">ReadOnly</span><span class="kwrd">="True"</span> <span class="attr">SortExpression</span><span class="kwrd">="Id"</span> <span class="kwrd">/&gt;</span></pre>
<pre class="alt">                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">="Name"</span> <span class="attr">HeaderText</span><span class="kwrd">="Name"</span> <span class="attr">SortExpression</span><span class="kwrd">="Name"</span> <span class="kwrd">/&gt;</span></pre>
<pre>                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">="Email"</span> <span class="attr">HeaderText</span><span class="kwrd">="Email"</span> <span class="attr">SortExpression</span><span class="kwrd">="Email"</span> <span class="kwrd">/&gt;</span></pre>
<pre class="alt">                <span class="kwrd">&lt;</span><span class="html">asp:TemplateField</span> <span class="attr">HeaderText</span><span class="kwrd">="Approved"</span> <span class="attr">SortExpression</span><span class="kwrd">="Approved"</span><span class="kwrd">&gt;</span></pre>
<pre>                    <span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">                        <span class="kwrd">&lt;</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span><span class="kwrd">="DropDownListUser"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">AutoPostBack</span><span class="kwrd">="False"</span> </pre>
<pre>                            <span class="attr">SelectedValue</span><span class="kwrd">='&lt;%# Bind("Approved") %&gt;'</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">                            <span class="kwrd">&lt;</span><span class="html">asp:ListItem</span> <span class="attr">Text</span><span class="kwrd">="Yes"</span> <span class="attr">Value</span><span class="kwrd">="True"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:ListItem</span><span class="kwrd">&gt;</span></pre>
<pre>                            <span class="kwrd">&lt;</span><span class="html">asp:ListItem</span> <span class="attr">Text</span><span class="kwrd">="No"</span> <span class="attr">Value</span><span class="kwrd">="False"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:ListItem</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">                        <span class="kwrd">&lt;/</span><span class="html">asp:DropDownList</span><span class="kwrd">&gt;</span></pre>
<pre>                    <span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">                <span class="kwrd">&lt;/</span><span class="html">asp:TemplateField</span><span class="kwrd">&gt;</span></pre>
<pre>            <span class="kwrd">&lt;/</span><span class="html">Columns</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">asp:GridView</span><span class="kwrd">&gt;</span></pre>
<pre>    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
<pre class="alt">    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span></pre>
<pre><span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span></pre>
<pre class="
alt"><span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { 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>&nbsp;</p>
<p>And, when you run this code (assuming you have a simple business object that returns some data), you get this:</p>
<p>&nbsp;</p>
<p><a href="http://peterkellner.net/wp/wp-content/uploads/2008/08/x1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="92" alt="x" src="http://peterkellner.net/wp/wp-content/uploads/2008/08/x-thumb1.png" width="314" border="0"/></a> </p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/08/05/assign-dropdownlist-in-aspdotnet-to-gridview-in-objectdatasource/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using Using in c# ado.net business classes used with ObjectDataSource in ASP.NET 2.0</title>
		<link>http://peterkellner.net/2007/10/29/usingusinghowto/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=usingusinghowto</link>
		<comments>http://peterkellner.net/2007/10/29/usingusinghowto/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 01:28:57 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/10/29/usingusinghowto/</guid>
		<description><![CDATA[A short post and example on how to use the C# syntax Using.  The example is for an ado.net business object that can be used with an ObjectDataSource.  This saves you the trouble of disposing of your objects properly, as well as doing it at the right place.]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve been preaching for a long time that it&#8217;s best to use the Using pattern when working with anything that implements IDisposable.&#160; That way, you don&#8217;t have to worry about calling Dispose, or calling Close.&#160; The framework will just do it for you.&#160; I&#8217;ve answered this question on the forums several times so I thought I&#8217;d past some code I&#8217;m doing right now for simple ado.net stuff.&#160; It&#8217;s actually code that is inside a business object that I hook up to an ObjectDataSource in asp.net 2.0. </p>
<p>The code is posted below.&#160; I think you&#8217;ll get the idea.</p>
<p> <span id="more-83"></span>
<p>[<span style="color: #2b91af">DataObjectMethod</span>(<span style="color: #2b91af">DataObjectMethodType</span>.Select, <span style="color: blue">false</span>)]</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">DataObjectCategory</span>&gt; GetByPrimaryKey(<span style="color: blue">int</span> id)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">string</span> sqlWhere = <span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&quot; WHERE id={0} &quot;</span>, id);</p>
<p style="margin: 0px"><span style="color: blue">return</span> GetByRawSQL(<span style="color: blue">string</span>.Empty, sqlWhere);</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">private</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">DataObjectCategory</span>&gt; GetByRawSQL(<span style="color: blue">string</span> sortData, <span style="color: blue">string</span> sqlWhereClause)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: blue">string</span> sqlBaseString = <span style="color: #a31515">&quot;SELECT ContentTypeId,Description,SortOrder,Id FROM Category &quot;</span>;</p>
<p style="margin: 0px"><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">DataObjectCategory</span>&gt; DataTemplateODSList = <span style="color: blue">new</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">DataObjectCategory</span>&gt;();</p>
<p style="margin: 0px"><span style="color: blue">using</span> (<span style="color: #2b91af">SqlConnection</span> conn = <span style="color: blue">new</span> <span style="color: #2b91af">SqlConnection</span>(connectionString))</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; conn.Open();</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">if</span> (!<span style="color: #2b91af">String</span>.IsNullOrEmpty(sqlWhereClause))</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; sqlBaseString += sqlWhereClause;</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">SqlCommand</span> cmd = <span style="color: blue">new</span> <span style="color: #2b91af">SqlCommand</span>(sqlBaseString, conn))</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">SqlDataReader</span> reader = cmd.ExecuteReader())</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">try</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">while</span> (reader.Read())</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> contenttypeid = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">string</span> description = reader.IsDBNull(1) ? <span style="color: #a31515">&quot;&quot;</span> : reader.GetString(1);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> sortorder = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> id = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DataObjectCategory</span> td = <span style="color: blue">new</span> <span style="color: #2b91af">DataObjectCategory</span>(contenttypeid,</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; description, sortorder, id);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DataTemplateODSList.Add(td);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ee)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">ApplicationException</span>(ee.ToString());</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">}</p>
</p></div>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/10/29/usingusinghowto/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Set the Default Value of a DropDownList in an ASP.NET Page</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dropdownlistdefaultsetting</link>
		<comments>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 17:44:13 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/</guid>
		<description><![CDATA[<p> This article shows how to set the default Value of a DropDownList Control when using asp.net 2.0.  It uses the DataBound event to do it.  A full page example which can be cut and paste is included</p>]]></description>
			<content:encoded><![CDATA[<h2>(Using Membership ObjectDataSource From MSDN Article)</h2>
<p>I&#8217;m doing a project where I have lots of DropDownList&#8217;s on a page and want a simple way to set the initial values based on some known value.&#160; The DropDownLists are retrieved using ObjectDataSource but I don&#8217;t want the first value displayed.&#160; I wrestled some with how to do this using page_load or page_prerender but didn&#8217;t come up with good solutions.&#160; I did finally    <br />decide that programming the databound event of the dropdownlist was probably the best way to go. </p>
<p>The solution is pasted below.&#160; The MembershipUtilities.MembershipODS c# code can be downloaded from MSDN or on my web site at the following location.&#160; </p>
<p> <span id="more-80"></span>
<p><a href="http://peterkellner.net/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/">http://peterkellner.net/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/</a>.</p>
<p> <!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode"><span class="asp">&lt;%@ Page Language=”C#” %&gt;</span>
<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> “<span class="attr">-</span>//<span class="attr">W3C</span>//<span class="attr">DTD</span> <span class="attr">XHTML</span> <span class="attr">1</span>.<span class="attr">0</span> <span class="attr">Transitional</span>//<span class="attr">EN</span>”

  “<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">TR</span>/<span class="attr">xhtml1</span>/<span class="attr">DTD</span>/<span class="attr">xhtml1-transitional</span>.<span class="attr">dtd</span>”<span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">protected</span> <span class="kwrd">void</span> DropDownListUser_DataBound(<span class="kwrd">object</span> sender, EventArgs e)

    {
        DropDownListUser.SelectedIndex =
          DropDownListUser.Items.IndexOf
          (DropDownListUser.Items.FindByValue(Context.User.Identity.Name));
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span>=”<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">1999</span>/<span class="attr">xhtml</span>” <span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>DropDownList Initialize<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span>=”<span class="attr">form1</span>″ <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span>=”<span class="attr">DropDownListUser</span>” <span class="attr">runat</span>=”<span class="attr">server</span>”
          <span class="attr">DataSourceID</span>=”<span class="attr">ObjectDataSourceUser</span>”
          <span class="attr">DataTextField</span>=”<span class="attr">UserName</span>” <span class="attr">DataValueField</span>=”<span class="attr">UserName</span>”
          <span class="attr">OnDataBound</span>=”<span class="attr">DropDownListUser_DataBound</span>”<span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:DropDownList</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:ObjectDataSource</span> <span class="attr">ID</span>=”<span class="attr">ObjectDataSourceUser</span>” <span class="attr">runat</span>=”<span class="attr">server</span>”
          <span class="attr">SelectMethod</span>=”<span class="attr">GetMembers</span>”
          <span class="attr">TypeName</span>=”<span class="attr">MembershipUtilities</span>.<span class="attr">MembershipUserODS</span>”<span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">sortData</span>” <span class="attr">Type</span>=”<span class="attr">String</span>” <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:ObjectDataSource</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Silicon Valley Code Camp Integrates the DevExpress Cloud Control for Sessions</title>
		<link>http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cloudcontrolforcodecamp</link>
		<comments>http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 19:11:58 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Atlas/AJAX]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/</guid>
		<description><![CDATA[Using the DevExpress CloudControl in the ASP.NET 2.0 Silicon Valley Code Camp's web site was easy.  In this short post, you'll hear about the details and see some code.]]></description>
			<content:encoded><![CDATA[<p>Recently, is seems that many web sites and blogs are starting to use a navigation technique where you have multiple hyperlinks grouped in a box, with size, color, or brightness giving some meaning.&#160; I like this very much and have been on the lookout for a while for a control to do this in ASP.NET.&#160; Turns out, DevExpress has one!&#160; It&#8217;s called the CloudControl and you can read more about it at the following URL.</p>
<p> <span id="more-74"></span>
<p>&#160;<a href="http://www.devexpress.com/Products/NET/WebForms/ASPxCloudControl/Index.xml">http://www.devexpress.com/Products/NET/WebForms/ASPxCloudControl/Index.xml</a></p>
<p>So, now, where to use it?&#160; Code Camp of course!&#160; Now, if you browse to the Sessions listing, you&#8217;ll see the DevExpress Cloud Control in use.</p>
<p><img alt="Silicon Valley Code Camp Cloud Control" src="http://peterkellner.net/wp/Images/misc/cloudcontrol.jpg" /></p>
<p>You can see this control in action at our web site here:&#160; <br /><a href="http://www.siliconvalley-codecamp.com/Sessions.aspx">     <br />http://www.siliconvalley-codecamp.com/Sessions.aspx</a></p>
<p>My experience with using this control was great!&#160; Easy to setup.&#160; Below is all the code I needed on my asp page to make it happen.</p>
<p>&#160;<!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1 &lt;\cf3 dxcc\cf1 :\cf3 ASPxCloudControl\cf0  \cf5 ID\cf1 =&#8221;ASPxCloudControl1&#8243;\cf0  \cf5 runat\cf1 =&#8221;server&#8221;\cf0  \par ??           \cf5 DataSourceID\cf1 =&#8221;ObjectDataSourceCloudControl&#8221;\cf0  \cf5 ShowValues\cf1 =&#8221;True&#8221;\cf0  \par ??           \cf5 HorizontalAlign\cf1 =&#8221;NotSet&#8221;\cf0  \cf5 TextField\cf1 =&#8221;TagName&#8221;\cf0  \cf5 ValueField\cf1 =&#8221;TagCount&#8221;\cf0  \par ??           \cf5 NavigateUrlField\cf1 =&#8221;TagId&#8221;\cf0  \par ??           \cf5 NavigateUrlFormatString\cf1 =&#8221;Sessions.aspx?sortby=title&amp;by=category&amp;tag=\{0\}&#8221;\cf0  \par ??           \cf5 ToolTip\cf1 =&#8221;CloudControl Provided From DevExpress&#8221;&gt;\par ??\cf0                 \cf1 &lt;\cf3 RankProperties\cf1 &gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                     \cf1 &lt;\cf3 dxcc\cf1 :\cf3 RankProperties\cf0  \cf1 /&gt;\par ??\cf0                 \cf1 &lt;/\cf3 RankProperties\cf1 &gt;\par ??\cf0         \cf1 &lt;/\cf3 dxcc\cf1 :\cf3 ASPxCloudControl\cf1 &gt;\par ??\cf0         \cf1 &lt;\cf3 asp\cf1 :\cf3 ObjectDataSource\cf0  \cf5 ID\cf1 =&#8221;ObjectDataSourceCloudControl&#8221;\cf0  \cf5 runat\cf1 =&#8221;server&#8221;\cf0  \par ??            \cf5 SelectMethod\cf1 =&#8221;GetAllTags&#8221;\cf0  \cf5 TypeName\cf1 =&#8221;CodeCampSV.SessionTagsODS&#8221;&gt;\par ??\cf0         \cf1 &lt;/\cf3 asp\cf1 :\cf3 ObjectDataSource\cf1 &gt;}<br />
&#8211;></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 52</span>&#160;<span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">ASPxCloudControl</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ASPxCloudControl1&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 53</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">DataSourceID</span><span style="color: blue">=&quot;ObjectDataSourceCloudControl&quot;</span> <span style="color: red">ShowValues</span><span style="color: blue">=&quot;True&quot;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 54</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">HorizontalAlign</span><span style="color: blue">=&quot;NotSet&quot;</span> <span style="color: red">TextField</span><span style="color: blue">=&quot;TagName&quot;</span> <span style="color: red">ValueField</span><span style="color: blue">=&quot;TagCount&quot;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 55</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">NavigateUrlField</span><span style="color: blue">=&quot;TagId&quot;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 56</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">NavigateUrlFormatString</span><span style="color: blue">=&quot;Sessions.aspx?sortby=title&amp;by=category&amp;tag={0}&quot;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 57</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">ToolTip</span><span style="color: blue">=&quot;CloudControl Provided From DevExpress&quot;&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 58</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">RankProperties</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 59</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 60</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 61</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 62</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 63</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 64</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 65</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">RankProperties</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 66</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: #a31515">RankProperties</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 67</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: #a31515">dxcc</span><span style="color: blue">:</span><span style="color: #a31515">ASPxCloudControl</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 68</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ObjectDataSource</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ObjectDataSourceCloudControl&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 69</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">SelectMethod</span><span style="color: blue">=&quot;GetAllTags&quot;</span> <span style="color: red">TypeName</span><span style="color: blue">=&quot;CodeCampSV.SessionTagsODS&quot;&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 70</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ObjectDataSource</span><span style="color: blue">&gt;</span></p>
</p></div>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">This is my first trip into the Developer Express toolbox and so far, I&#8217;m very impressed!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/09/04/cloudcontrolforcodecamp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft ASP.NET Member/Role Management with IIS (VB Version)</title>
		<link>http://peterkellner.net/2007/02/15/membershipodsvb/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=membershipodsvb</link>
		<comments>http://peterkellner.net/2007/02/15/membershipodsvb/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 20:08:16 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/02/15/membershipodsvb/</guid>
		<description><![CDATA[<p>Back in January of 2006, I published on
<a href="http://peterkellner.net/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/">
MSDN an article and source code for managing ASP.NET 2.0 Membership users with
an ObjectDataSource.</a>&#160; Since I&#39;m not much of a VB person, I only
published them in c#.&#160; since then, I&#39;ve had hundreds of requests for this
code in VB.&#160; Until now, I&#39;ve had to send an excuse for not having it.&#160;
Now, thanks to Dave at <a href="http://www.tangiblesoftwaresolutions.com/">
Tangible Solutions Software</a>,
we now have a VB version.</p>]]></description>
			<content:encoded><![CDATA[<h2>The Visual Basic Version of the Objects!</h2>
<p>Back in January of 2006, I published on <a href="http://peterkellner.net/2006/01/09/microsoft-aspnet-20-memberrole-management-with-iis/">MSDN an article and source code for managing ASP.NET 2.0 Membership users with an ObjectDataSource.</a>&#160; Since I&#8217;m not much of a VB person, I only published them in c#.&#160; since then, I&#8217;ve had hundreds of requests for this code in VB.&#160; Until now, I&#8217;ve had to send an excuse for not having it. Now, thanks to Dave at&#160; <a href="http://www.tangiblesoftwaresolutions.com/">Tangible Solutions Software</a>, we now have a VB version.&#160; Dave converted it with there conversion software called <em>Instant VB</em>.</p>
<p class="style1">The following zip file includes these VB objects along with a very simple aspx page in VB.&#160; It does not include any more complete examples of using the objects because the code associated with the aspx pages I wrote is all in c#.&#160; If anyone wants to convert the other pages, I&#8217;d be happy to post those also.</p>
<p class="style1">Thanks Dave and Thanks Tangible Solutions!    <br /><a href="http://peterkellner.net/DownLoads/MembershipEditorVB.zip">     <br />http://peterkellner.net/DownLoads/MembershipEditorVB.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/02/15/membershipodsvb/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Rock And Roll Code Camp Presentation</title>
		<link>http://peterkellner.net/2007/02/01/codecampla07/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=codecampla07</link>
		<comments>http://peterkellner.net/2007/02/01/codecampla07/#comments</comments>
		<pubDate>Fri, 02 Feb 2007 02:13:27 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2007/02/01/codecampla07/</guid>
		<description><![CDATA[Code Camp Presentation at LA's Rock and Roll Code Camp.  Lots of nuts and bolts about using ObjectDataSoruce including a real life
example using the enterprise data block.]]></description>
			<content:encoded><![CDATA[<p><strong>Rock And Roll Code Camp in Los Angeles Presentation</strong></p>
<p>This is the first time I&#8217;ve presented this material. I&#8217;ve presented on several previous occassions the basic    <br />material on how to build an ObjectDataSource class from scratch but this time was different. Inspired by people     <br />often asking me &quot;what good is the ObjectDataSource&quot;, I decided to create a useful example. Since the ObjectDataSource is inherently a complex abstraction, creating a real life demo that can be presented in a short amount of time is a challenge. In this presntation, I hopefully rose to the challenge. Below is the abstract along with the URL to the actual codecamp. Below that is a link to the project that was created at class for     <br />anyone interested in seeing the material.</p>
<p> <span id="more-47"></span>
<p>Lots of nuts and bolts about using ObjectDataSoruce including a real life example using the enterprise data block (NetTiers and CodeSmith).</p>
<p><a href="http://www.socalcodecamp.com/session.aspx?sid=20a9c60e-9193-47bb-aed1-d756afbbd730">     <br />Build an ASP.NET 2.0 ObjectDataSource From Scratch and Use it with a DAL (NetTiers)</a></p>
<p><a href="http://www.socalcodecamp.com/sessions.aspx">     <br />http://www.socalcodecamp.com/sessions.aspx</a></p>
<p>And, Here is the Project Files.&#160; it includes all the .nettiers created code also.&#160; Not easy to build, but you will get the idea.&#160; The project to look at in specific would be the one named: JustODSWeb.&#160; All the others are just .NetTiers support.   <br /><a href="http://peterkellner.net/DownLoads/CodeCampJan07LA.zip">     <br />http://peterkellner.net/DownLoads/CodeCampJan07LA.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2007/02/01/codecampla07/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Improved Fast Access to Small Lists On ASPX Pages</title>
		<link>http://peterkellner.net/2006/10/27/smalllistaccessimproved/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=smalllistaccessimproved</link>
		<comments>http://peterkellner.net/2006/10/27/smalllistaccessimproved/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 19:34:42 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/10/27/smalllistaccessimproved/</guid>
		<description><![CDATA[The article below has a minor improvement to the previous article listed on this web site. Specifically, the previous article used the DropDownList as a mechanism to actually retrieve the data for the purposes of storing it in a local Dictionary. This article simply calls the ObjectDataSource directly to retrieve an IEnumerable type and iterates over that. Below is article with the updates.  (Original Article is: <a href="http://peterkellner.net/2006/08/30/smalllistaccess/">http://peterkellner.net/2006/08/30/smalllistaccess/</a>)]]></description>
			<content:encoded><![CDATA[<p align="left">The article below has a minor improvement to the previous article listed on this web site. Specifically, the previous article used the DropDownList as a mechanism to actually retrieve the data for the purposes of storing it in a local Dictionary. This article simply calls the ObjectDataSource directly to retrieve an IEnumerable type and iterates over that. Below is article with the updates. (Original Article is: <a href="http://peterkellner.net/2006/08/30/smalllistaccess/">http://peterkellner.net/2006/08/30/smalllistaccess/</a>)</p>
<p align="left">Most data driven web sites have to manage lots of small lists. Examples include things like states, countries, levels, and even things like sex where you may only have two choices. (especially if you have internationalization issues). The simplest way to store this information is in static lists simply defined programatically. Below is an example of this.</p>
<p> <span id="more-39"></span>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span>[] MonthNames =</pre>
<pre>   <span class="kwrd">new</span> <span class="kwrd">string</span>[] { “January”,“February”,“March”,</pre>
<pre class="alt">       “April”,“May”,“June”,“July”,</pre>
<pre>       “August”,“September”,“October”,“November”,“December”};</pre>
</div>
<p align="left">This works, but requires you modify your code in order to update a list. Not good in my opinion.</p>
<p align="left">So, the other solution is to store the information in a database table. Many people will say that&#8217;s overkill, but as long as you Cache the information, performance will not suffer and you gain lots of flexability.</p>
<h2>How to Cache Lists in a Database</h2>
<h3>Cache the List</h3>
<p>To cache the list I suggest using an ObjectDataSource with Cache set and then force a load of the ObjectDataSource by calling the Select Method, then using the IEnumerable type, iterate over the ObjectDataSource&#8217;s assigned type.</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">&lt;</span><span class="html">asp:ObjectDataSource</span> <span class="attr">ID</span>=”<span class="attr">ObjectDataSource1</span>″ <span class="attr">runat</span>=”<span class="attr">server</span>”</pre>
<pre>  <span class="attr">CacheDuration</span>=”<span class="attr">30</span>″ <span class="attr">EnableCaching</span>=”<span class="attr">True</span>”</pre>
<pre class="alt">  <span class="attr">SelectMethod</span>=”<span class="attr">GetData</span>”</pre>
<pre>  <span class="attr">TypeName</span>=”<span class="attr">DataSetLevelsTableAdapters</span>.<span class="attr">SessionLevelsTableAdapter</span>”<span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">asp:ObjectDataSource</span><span class="kwrd">&gt;</span></pre>
</div>
<p>The DataSource TypeName is simply a typed dataset which retrieves a resultset with a primary key and a description.</p>
<h3>Use the Cached List on an ASPX Page</h3>
<p>To use the cache list on the page, I first store what is in the DropDownList into a Dictionary which I can later reference on the page. Here is what I do in the Page_Load event.</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">partial</span>  <span class="kwrd">class</span> Sessions : System.Web.UI.Page</pre>
<pre>{</pre>
<pre class="alt">   <span class="kwrd">protected</span> Dictionary&lt;<span class="kwrd">int</span>, <span class="kwrd">string</span>&gt; SessionLevelsDictionary;</pre>
<pre>   <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)</pre>
<pre class="alt">   {</pre>
<pre>      SessionLevelsDictionary =</pre>
<pre class="alt">         <span class="kwrd">new</span> Dictionary&lt;<span class="kwrd">int</span>, <span class="kwrd">string</span>&gt;();</pre>
<pre>         IEnumerable someData = ObjectDataSource1.Select();</pre>
<pre class="alt">         <span class="kwrd">foreach</span> (StuffData stuffData <span class="kwrd">in</span> someData)</pre>
<pre>         {</pre>
<pre class="alt">            SessionLevelsDictionary.Add</pre>
<pre>            (stuffData.Id,stuffData.Name);</pre>
<pre class="alt">         }</pre>
</div>
<p>Now, I have in the page class a reference to all the values I may want to use on the page. Say, for example I have a Repeater control that is going to display 200 rows of data that includes a foreign key to one of my small list tables. I want to show the data in a Label control but don&#8217;t want to have any codebehind to set the data. Here is how I can access my dictionary to perform this trick.</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">&lt;</span><span class="html">asp:Label</span> <span class="attr">ID</span>=”<span class="attr">Label4</span>″ <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">Width</span>=”<span class="attr">90</span>″</pre>
<pre> <span class="attr">Text</span>=’&amp;<span class="attr">lt</span>;%# (<span class="attr">string</span>) <span class="attr">SessionLevelsDictionary</span>[(<span class="attr">int</span>) <span class="attr">Eval</span>(<span class="kwrd">&quot;SessionLevel_id&quot;</span>)] %&amp;<span class="attr">gt</span>;‘<span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">asp:Label</span><span class="kwrd">&gt;</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/10/27/smalllistaccessimproved/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Get SqlDataSource To Retrieve DefaultValue of Current User (ExpressionBuilder with ASP.NET 2.0)</title>
		<link>http://peterkellner.net/2006/09/18/expressionbuilderidentity/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=expressionbuilderidentity</link>
		<comments>http://peterkellner.net/2006/09/18/expressionbuilderidentity/#comments</comments>
		<pubDate>Mon, 18 Sep 2006 16:50:07 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[How Things Work]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/09/18/expressionbuilderidentity/</guid>
		<description><![CDATA[<p>
This article shows how to use Expression Builders in ASP.NET 2.0 to retrieve the current logged in user.  DataBinding will not work so Expression Builders is the ticket.  A small source file is created, the refernces to web.config are shown and a simple example is built.</p>]]></description>
			<content:encoded><![CDATA[<h2>Abstract</h2>
<p>This article shows how to use Expression Builders in ASP.NET 2.0 to retrieve the current logged in user. DataBinding will not work so Expression Builders is the ticket. A small source file is created, the references to web.config are shown and a simple example is built.</p>
<h2>The Problem</h2>
<p>I recently was looking at unanswered posts in the asp.net forum, specifically this one: <a href="http://forums.asp.net/thread/1402259.aspx">http://forums.asp.net/thread/1402259.aspx</a>. I thought I     <br />understood how databinding and expressions worked, but just wanted to check myself. So, I made a simple example     <br />web page just like the post shows. (see below)</p>
<p> <span id="more-33"></span>
<pre class="csharpcode"><span class="asp">&lt;%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %&gt;</span>
<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> “<span class="attr">-</span>//<span class="attr">W3C</span>//<span class="attr">DTD</span> <span class="attr">XHTML</span> <span class="attr">1</span>.<span class="attr">0</span> <span class="attr">Transitional</span>//<span class="attr">EN</span>” “<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">TR</span>/<span class="attr">xhtml1</span>/<span class="attr">DTD</span>/<span class="attr">xhtml1-transitional</span>.<span class="attr">dtd</span>”<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span>=”<span class="attr">http:</span>//<span class="attr">www</span>.<span class="attr">w3</span>.<span class="attr">org</span>/<span class="attr">1999</span>/<span class="attr">xhtml</span>”<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">id</span>=”<span class="attr">Head1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>Untitled Page<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span>=”<span class="attr">form1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>”<span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span>=”<span class="attr">GridView1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">AutoGenerateColumns</span>=”<span class="attr">False</span>” <span class="attr">DataSourceID</span>=”<span class="attr">SqlDataSource1</span>?<span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span>=”<span class="attr">Username</span>” <span class="attr">HeaderText</span>=”<span class="attr">Username</span>” <span class="attr">SortExpression</span>=”<span class="attr">Username</span>” <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">asp:GridView</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span>=”<span class="attr">SqlDataSource1</span>? <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">ConnectionString</span>=”&amp;<span class="attr">lt</span>;%$ <span class="attr">ConnectionStrings:CodeCampSV06</span> %&amp;<span class="attr">gt</span>;“
                <span class="attr">SelectCommand</span>=”<span class="attr">SELECT</span> [<span class="attr">Username</span>], [<span class="attr">Email</span>] <span class="attr">FROM</span> [<span class="attr">Attendees</span>] <span class="attr">WHERE</span> ([<span class="attr">Username</span>] = @<span class="attr">Username</span>)”<span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">Username</span>” <span class="attr">Type</span>=”<span class="attr">String</span>” <span class="attr">DefaultValue</span>=”&amp;<span class="attr">lt</span>;% <span class="attr">User</span>.<span class="attr">Identity</span>.<span class="attr">Name</span> %&amp;<span class="attr">gt</span>;“  <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<p>Then, I ran it through Lutz Roeder&#8217;s .NET Reflector and got the following from the code.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode"><span class="kwrd">private</span> Parameter __BuildControl__control6()
{
    Parameter parameter1 = <span class="kwrd">new</span> Parameter();
    parameter1.Name = “Username”;
    parameter1.Type = TypeCode.String;
    parameter1.DefaultValue = “&lt;% User.Identity.Name %&gt;”;
    <span class="kwrd">return</span> parameter1;
}</pre>
<p>It&#8217;s pretty obvious that unless there is a username of the literal string &quot;&lt;% User.Identity.Name %&gt;&quot; no records will be find. This simply means that the build provider asp.net uses is not generating any code for us with sqldatasource that will help with the DefaultValue of parameters in a SqlDataSource.</p>
<h2>The Solution</h2>
<p>Expression Builder to the rescue!</p>
<p>To solve the problem, we need to build a simple expression builder. Without going into all the details of what an expression builder is, all you need to do is put the following code in your app_code directory and call it something like ExpressionBuilderIdentity.cs.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Data;
<span class="kwrd">using</span> System.Configuration;
<span class="kwrd">using</span> System.Web;
<span class="kwrd">using</span> System.Web.Security;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> System.Web.UI.WebControls;
<span class="kwrd">using</span> System.Web.UI.WebControls.WebParts;
<span class="kwrd">using</span> System.Web.UI.HtmlControls;
<span class="kwrd">using</span> System.Web.Compilation;
<span class="kwrd">using</span> System.CodeDom;

<span class="kwrd">public</span> <span class="kwrd">class</span> ExpressionBuilderIdentity : ExpressionBuilder
{
    <span class="kwrd">public</span> <span class="kwrd">override</span> System.CodeDom.CodeExpression GetCodeExpression(
        BoundPropertyEntry entry, <span class="kwrd">object</span> parsedData, ExpressionBuilderContext context)
    {
        CodeTypeReferenceExpression targetClass =
            <span class="kwrd">new</span> CodeTypeReferenceExpression(<span class="kwrd">typeof</span>(ExpressionBuilderIdentity));
        <span class="kwrd">string</span> targetMethod = “GetIdentity”;
        CodeExpression methodParameter =
            <span class="kwrd">new</span> CodePrimitiveExpression(entry.Expression.Trim());
        <span class="kwrd">return</span> <span class="kwrd">new</span> CodeMethodInvokeExpression(
            targetClass, targetMethod, methodParameter);
    }

    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">object</span> GetIdentity(<span class="kwrd">string</span> param)
    {
        <span class="kwrd">string</span> returnString = <span class="kwrd">string</span>.Empty;

        <span class="kwrd">if</span> (param.ToLower().Equals(“name”))
        {
            returnString = HttpContext.Current.User.Identity.Name;
        }

        <span class="kwrd">return</span> returnString;
    }
}</pre>
<p>Then, you need to add a reference to it in your web.config as follows:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">compilation</span> <span class="attr">debug</span>=“<span class="attr">true</span>“<span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">expressionBuilders</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">expressionPrefix</span>=“<span class="attr">UserIdentity</span>“ <span class="attr">type</span>=“<span class="attr">ExpressionBuilderIdentity</span>, <span class="attr">__code</span>“<span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">expressionBuilders</span><span class="kwrd">&gt;</span>
      …</pre>
<p>Then, specify the SqlDataSource as follows:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span>=”<span class="attr">SqlDataSource1</span>″ <span class="attr">runat</span>=”<span class="attr">server</span>” <span class="attr">ConnectionString</span>=”&amp;<span class="attr">lt</span>;%$ <span class="attr">ConnectionStrings:CodeCampSV06</span> %&amp;<span class="attr">gt</span>;“ <span class="attr">SelectCommand</span>=”<span class="attr">SELECT</span> [<span class="attr">Username</span>], [<span class="attr">Email</span>] <span class="attr">FROM</span> [<span class="attr">Attendees</span>] <span class="attr">WHERE</span> ([<span class="attr">Username</span>] = @<span class="attr">Username</span>)”<span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>=”<span class="attr">Username</span>” <span class="attr">Type</span>=”<span class="attr">String</span>”
                <span class="attr">DefaultValue</span>=”&amp;<span class="attr">lt</span>;%$ <span class="attr">UserIdentity:name</span> %&amp;<span class="attr">gt</span>;“ <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">SelectParameters</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span></pre>
<p>And, Presto, it works!</p>
<h2>Summary</h2>
<p>Anytime you are using one of the new datasourceID controls, you need to use expressions rather than databinding if you want to reference outside variables. Creating the code is fairly straight forward and lends itself to lots of cool possibilities.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/09/18/expressionbuilderidentity/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Rendering Images With IIS Verses an ASP.NET 2.0 Handler</title>
		<link>http://peterkellner.net/2006/09/04/iisaspnetperf/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=iisaspnetperf</link>
		<comments>http://peterkellner.net/2006/09/04/iisaspnetperf/#comments</comments>
		<pubDate>Tue, 05 Sep 2006 05:38:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/09/04/iisaspnetperf/</guid>
		<description><![CDATA[This article will compare the difference between rendering images using an HttpHandler and IIS.  It will show the different request processing times for a small, medium and large bmp file.  It also discusses using the DefaultHttpHandler.]]></description>
			<content:encoded><![CDATA[<h2>Performance Comparison</h2>
<p>Recently, I&#8217;ve been wondering what the difference is between rendering an image using IIS&#8217;s built in file handling capabilities, or using the asp.net with a custom handler. I decided to do a little test program to simply see the difference in clock time for processing such requests. The results of this test clearly show that IIS is faster. Sometimes a little, and sometimes a lot. I decided to test three size images, and run them each 10 times. Often, there is a start up lag time so the iterations should wash that out.</p>
<p>The table below basically sums up the results pretty well. The resolution of my timer is not great so for small images (35KB), both IIS and the handler processed the image in under 15 milliseconds. There may be a difference but in   <br />my case, it was probably not measurable because of all the other time involved in the request. For Medium size images (550KB), difference is more consistent. Again, it&#8217;s a timer resolution problem that makes 15 milliseconds probably something related to a CPU click of sorts. For large images (5.6MB) you can clearly see a difference. The time it takes for the handler to process the image is almost double that of IIS.</p>
<p> <span id="more-32"></span>
<p><img src="http://peterkellner.net/images/IISASPNETPERF.jpg" width="609" height="497" /></p>
<p>Just for the fun of it, if you want to run a URL that has the program that generated these numbers, you can by going to the URL: <a href="http://livedemos.peterkellner.net/ASPNETIISTiming.aspx">http://livedemos.peterkellner.net/ASPNETIISTiming.aspx</a> and the numbers will recalculate live. A couple things to keep in mind here. First, the above URL is running on a hosted site with lots of other customers (specifically, it&#8217;s hosted at <a href="http://ultimahosts.net/">http://ultimahosts.net/</a> whom I recommend highly and it&#8217;s running with IIS 6.0.</p>
<p>If you want to experiment yourself with this, I&#8217;ve listed at the bottom of this article the class I associate with an ObjectDataSource to generate these numbers (as well as the HttpHandler and the aspx page). The tables are each GridView&#8217;s with incoming parameters to the ODS class of number of iterations and the image name in the /Images directory to process. It&#8217;s really very straight forward.</p>
<h2>Conclusions</h2>
<p>The conclusion is pretty obvious for large images. That is, IIS is better. There are times when you must use   <br />a handler such as when you want to watermark your images or do other custom rendering. If, however that is not    <br />necessary, better to rely on IIS to process the images. Something also to keep in mind is that if you use the    <br />Wild Card Forwarding Option in IIS (only available in IIS6, not IIS5.1), the DefaultHttpHandler will automatically    <br />get invoked for you on file types you do not specifically handle and those images will bounce back and get processed by    <br />IIS 6.0. Here is a good reference from <a href="http://www.leastprivilege.com/CommentView.aspx?guid=e37d2789-fb3f-4d05-ad25-496b88a2e3cb">Dominick Baier describing how that works</a>.</p>
<p>(GetWebData.cs) This is the class the ObjectDataSource References.</p>
<div style="border-bottom: #cccccc 1pt solid; border-left: #cccccc 1pt solid; padding-bottom: 1pt; padding-left: 1pt; width: 100%; padding-right: 1pt; font-family: courier new; background: #f5f5f5; color: black; font-size: 10pt; overflow: auto; border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; padding-top: 1pt">
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Collections.Generic;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.ComponentModel;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.IO;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Net;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Web;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> Summary description for GetWebData</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span></p>
<p style="margin: 0px">[<span style="color: teal">DataObject</span>(<span style="color: blue">true</span>)] <span style="color: green">// This attribute allows the ObjectDataSource wizard to see this class</span></p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">GetWebData</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> This is the Select Method used with the class.</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> filename should be the name of the file that is in the images directory</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;iterations&quot;&gt;&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;fileName&quot;&gt;&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;returns&gt;&lt;/returns&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; [<span style="color: teal">DataObjectMethod</span>(<span style="color: teal">DataObjectMethodType</span>.Select, <span style="color: blue">true</span>)]</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: teal">List</span>&lt;<span style="color: teal">ResultData</span>&gt; GetWebResults(<span style="color: blue">int</span> iterations, <span style="color: blue">string</span> fileName)</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">string</span> absUri = <span style="color: teal">HttpContext</span>.Current.Request.Url.AbsoluteUri;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">string</span> absoluteUri = absUri.Substring(0, absUri.LastIndexOf(<span style="color: maroon">&quot;/&quot;</span>));</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">List</span>&lt;<span style="color: teal">ResultData</span>&gt; list = <span style="color: blue">new</span> <span style="color: teal">List</span>&lt;<span style="color: teal">ResultData</span>&gt;(iterations);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">for</span> (<span style="color: blue">int</span> i = 0; i &lt; iterations; i++)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">ResultData</span> rd = <span style="color: blue">new</span> <span style="color: teal">ResultData</span>();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rd.FromASPNET1 = ProcessWebRequest(absoluteUri + <span style="color: maroon">&quot;/DisplayBMP.ashx?filename=&quot;</span> + fileName);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rd.FromIIS = ProcessWebRequest(absoluteUri + <span style="color: maroon">&quot;/Images/&quot;</span> + fileName);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; list.Add(rd);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> list;</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> This process the requestString passed in and returns</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> the number of ms it took to do that.&#160; It does nothing</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> with the results</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;param name=&quot;requestString&quot;&gt;</span><span style="color: green">complete URL</span><span style="color: gray">&lt;/param&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;returns&gt;</span><span style="color: green">milliseconds in process</span><span style="color: gray">&lt;/returns&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">double</span> ProcessWebRequest(<span style="color: blue">string</span> requestString)</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// used on each read operation (big, 1.5MB)</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// normally, one read is enough, but if it is</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// bigger than 1.5 MB, then it will simply to</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// multiple reads which should not affect timing</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// very much is my guess.</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] buf = <span style="color: blue">new</span> <span style="color: blue">byte</span>[1500000];</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// prepare the web page we will be asking for</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">HttpWebRequest</span> request = (<span style="color: teal">HttpWebRequest</span>)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">WebRequest</span>.Create(requestString);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">DateTime</span> startTime = <span style="color: teal">DateTime</span>.Now;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// execute the request</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">HttpWebResponse</span> response = (<span style="color: teal">HttpWebResponse</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; request.GetResponse();</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// we will read data via the response stream</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">Stream</span> resStream = response.GetResponseStream();</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> count;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">int</span> bytesRead = 0;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">do</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// fill the buffer with data</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; count = resStream.Read(buf, 0, buf.Length);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// make sure we read some data</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (count != 0)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bytesRead += count;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <span style="color: blue">while</span> (count &gt; 0); <span style="color: green">// any more data to read?</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">DateTime</span> stopTime = <span style="color: teal">DateTime</span>.Now;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: teal">TimeSpan</span> elapsedTime = stopTime &#8211; startTime;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> elapsedTime.TotalMilliseconds;</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> A simple class to be used with Generic List</span></p>
<p style="margin: 0px"><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">ResultData</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">double</span> FromASPNET;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">double</span> FromASPNET1</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get</span> { <span style="color: blue">return</span> <span style="color: teal">Math</span>.Floor(FromASPNET); }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">set</span> { FromASPNET = <span style="color: blue">value</span>; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">double</span> fromIIS;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">double</span> FromIIS</p>
<p style="margin: 0px">&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get</span> { <span style="color: blue">return</span> <span style="color: teal">Math</span>.Floor(fromIIS); }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">set</span> { fromIIS = <span style="color: blue">value</span>; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">}</p>
</p></div>
<p>&#160;</p>
<p>(DisplayBMP.ashx) The Handler I&#8217;m using for the comparison.</p>
<div style="border-bottom: #cccccc 1pt solid; border-left: #cccccc 1pt solid; padding-bottom: 1pt; padding-left: 1pt; width: 100%; padding-right: 1pt; font-family: courier new; background: #f5f5f5; color: black; font-size: 10pt; overflow: auto; border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; padding-top: 1pt">
<p style="margin: 0px"><span style="background: yellow">&lt;%</span><span style="color: blue">@</span> <span style="color: maroon">WebHandler</span> <span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot;</span> <span style="color: red">Class</span><span style="color: blue">=&quot;DisplayBMP&quot;</span>&#160; <span style="background: yellow">%&gt;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Web;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">DisplayBMP</span> : <span style="color: teal">IHttpHandler</span> {</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">void</span> ProcessRequest (<span style="color: teal">HttpContext</span> context) {</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">try</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">string</span> fileName = context.Server.MapPath(<span style="color: maroon">&quot;Images/medium.bmp&quot;</span>);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (<span style="color: teal">HttpContext</span>.Current.Request.QueryString[<span style="color: maroon">&quot;filename&quot;</span>] != <span style="color: blue">null</span>)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fileName = context.Server.MapPath(<span style="color: maroon">&quot;Images/&quot;</span> + <span style="color: teal">HttpContext</span>.Current.Request.QueryString[<span style="color: maroon">&quot;filename&quot;</span>]);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.Drawing.<span style="color: teal">Bitmap</span> bitMap = <span style="color: blue">new</span> System.Drawing.<span style="color: teal">Bitmap</span>(fileName);</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.IO.<span style="color: teal">MemoryStream</span> ms = <span style="color: blue">new</span> System.IO.<span style="color: teal">MemoryStream</span>();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bitMap.Save(ms, System.Drawing.Imaging.<span style="color: teal">ImageFormat</span>.Bmp);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] byteArray = <span style="color: blue">new</span> <span style="color: blue">byte</span>[ms.Length];</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ms.Position = 0;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ms.Read(byteArray, 0, <span style="color: teal">Convert</span>.ToInt32(ms.Length));</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ms.Close();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ms.Dispose();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bitMap.Dispose();</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Response.ContentType = <span style="color: maroon">&quot;image/bmp&quot;</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Response.BinaryWrite(byteArray);</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">catch</span> (<span style="color: teal">Exception</span> ee)</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: teal">ApplicationException</span>(ee.ToString());</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">finally</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">bool</span> IsReusable {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">get</span> {</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> <span style="color: blue">false</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;&#160;&#160; }</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">}</p>
</p></div>
<p>&#160;</p>
<p>(ASPNETIISTiming.aspx) The aspx page to pull it all together (nothing in the codebehind).</p>
<div style="border-bottom: #cccccc 1pt solid; border-left: #cccccc 1pt solid; padding-bottom: 1pt; padding-left: 1pt; width: 100%; padding-right: 1pt; font-family: courier new; background: #f5f5f5; color: black; font-size: 10pt; overflow: auto; border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; padding-top: 1pt">
<p style="margin: 0px"><span style="background: yellow">&lt;%</span><span style="color: blue">@</span> <span style="color: maroon">Page</span> <span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot;</span> <span style="color: red">MasterPageFile</span><span style="color: blue">=&quot;~/MasterPageNoHeadShot.master&quot;</span> <span style="color: red">AutoEventWireup</span><span style="color: blue">=&quot;true&quot;</span> <span style="color: red">CodeFile</span><span style="color: blue">=&quot;ASPNETIISTiming.aspx.cs&quot;</span> <span style="color: red">Inherits</span><span style="color: blue">=&quot;ASPNETIISTiming&quot;</span> <span style="color: red">Title</span><span style="color: blue">=&quot;Untitled Page&quot;</span> <span style="background: yellow">%&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Content</span> <span style="color: red">ID</span><span style="color: blue">=&quot;Content1&quot;</span> <span style="color: red">ContentPlaceHolderID</span><span style="color: blue">=&quot;ContentPlaceHolder1&quot;</span> <span style="color: red">Runat</span><span style="color: blue">=&quot;Server&quot;&gt;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: maroon">div</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">table</span> <span style="color: red">border</span><span style="color: blue">=&quot;1&quot;</span> <span style="color: red">cellpadding</span><span style="color: blue">=&quot;15&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">tr</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">colspan</span><span style="color: blue">=&quot;3&quot;</span> <span style="color: red">style</span><span style="color: blue">=&quot;text-align: center&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Time Shown is for comparing load time in milliseconds when loading an image from</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; IIS<span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; or using ASP.NET handler.<span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; For Further Discussion on this:<span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">HyperLink</span> <span style="color: red">ID</span><span style="color: blue">=&quot;HyperLink1&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">NavigateUrl</span><span style="color: blue">=&quot;http://peterkellner.net/IISASPNETPerf&quot;&gt;</span>http://peterkellner.net/IISASPNETPerf<span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">HyperLink</span><span style="color: blue">&gt;&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">tr</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">tr</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">style</span><span style="color: blue">=&quot;width: 100px&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Small Image (35KB)<span style="color: blue">&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">style</span><span style="color: blue">=&quot;width: 100px&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Medium Image (550KB)<span style="color: blue">&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">style</span><span style="color: blue">=&quot;width: 100px&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Large Image (5.6MB)<span style="color: blue">&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">tr</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">tr</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">style</span><span style="color: blue">=&quot;width: 100px&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">GridView</span> <span style="color: red">ID</span><span style="color: blue">=&quot;GridView1&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span><br />style=&quot;color: red;&quot;&gt;AutoGenerateColumns</span><span style="color: blue">=&quot;False&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">DataSourceID</span><span style="color: blue">=&quot;ObjectDataSourceSmall&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">Columns</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">BoundField</span> <span style="color: red">DataField</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: red">HeaderText</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: red">SortExpression</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">BoundField</span> <span style="color: red">DataField</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: red">HeaderText</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: red">SortExpression</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">Columns</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">GridView</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">style</span><span style="color: blue">=&quot;width: 100px&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">GridView</span> <span style="color: red">ID</span><span style="color: blue">=&quot;GridView2&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">AutoGenerateColumns</span><span style="color: blue">=&quot;False&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">DataSourceID</span><span style="color: blue">=&quot;ObjectDataSourceMedium&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">Columns</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">BoundField</span> <span style="color: red">DataField</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: red">HeaderText</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: red">SortExpression</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">BoundField</span> <span style="color: red">DataField</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: red">HeaderText</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: red">SortExpression</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">Columns</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">GridView</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">td</span> <span style="color: red">style</span><span style="color: blue">=&quot;width: 100px&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">GridView</span> <span style="color: red">ID</span><span style="color: blue">=&quot;GridView3&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">AutoGenerateColumns</span><span style="color: blue">=&quot;False&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">DataSourceID</span><span style="color: blue">=&quot;ObjectDataSourceLarge&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">Columns</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">BoundField</span> <span style="color: red">DataField</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: red">HeaderText</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: red">SortExpression</span><span style="color: blue">=&quot;FromIIS&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">BoundField</span> <span style="color: red">DataField</span><span style="color: blue">=&quot;FromASPNET1&quot;       <br /></span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: red">SortExpression</span><span style="color: blue">=&quot;FromASPNET1&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">Columns</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">GridView</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">td</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">tr</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">table</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Button</span> <span style="color: red">ID</span><span style="color: blue">=&quot;Button1&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">Text</span><span style="color: blue">=&quot;Recalculate Times&quot;</span> <span style="color: red">Visible</span><span style="color: blue">=&quot;False&quot;</span> <span style="color: blue">/&gt;&lt;</span><span style="color: maroon">br</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">&amp;nbsp;&amp;nbsp;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ObjectDataSource</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ObjectDataSourceMedium&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">SelectMethod</span><span style="color: blue">=&quot;GetWebResults&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">TypeName</span><span style="color: blue">=&quot;GetWebData&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">SelectParameters</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Parameter</span> <span style="color: red">DefaultValue</span><span style="color: blue">=&quot;10&quot;</span> <span style="color: red">Name</span><span style="color: blue">=&quot;iterations&quot;</span> <span style="color: red">Type</span><span style="color: blue">=&quot;Int32&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Parameter</span> <span style="color: red">DefaultValue</span><span style="color: blue">=&quot;medium.bmp&quot;</span> <span style="color: red">Name</span><span style="color: blue">=&quot;fileName&quot;</span> <span style="color: red">Type</span><span style="color: blue">=&quot;String&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">SelectParameters</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ObjectDataSource</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ObjectDataSource</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ObjectDataSourceSmall&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">SelectMethod</span><span style="color: blue">=&quot;GetWebResults&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">TypeName</span><span style="color: blue">=&quot;GetWebData&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">SelectParameters</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Parameter</span> <span style="color: red">DefaultValue</span><span style="color: blue">=&quot;10&quot;</span> <span style="color: red">Name</span><span style="color: blue">=&quot;iterations&quot;</span> <span style="color: red">Type</span><span style="color: blue">=&quot;Int32&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Parameter</span> <span style="color: red">DefaultValue</span><span style="color: blue">=&quot;small.bmp&quot;</span> <span style="color: red">Name</span><span style="color: blue">=&quot;fileName&quot;</span> <span style="color: red">Type</span><span style="color: blue">=&quot;String&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">SelectParameters</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ObjectDataSource</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ObjectDataSource</span> <span style="color: red">ID</span><span style="color: blue">=&quot;ObjectDataSourceLarge&quot;</span> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;</span> <span style="color: red">SelectMethod</span><span style="color: blue">=&quot;GetWebResults&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red">TypeName</span><span>=&quot;GetWebData&quot;&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">SelectParameters</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Parameter</span> <span style="color: red">DefaultValue</span><span style="color: blue">=&quot;10&quot;</span> <span style="color: red">Name</span><span style="color: blue">=&quot;iterations&quot;</span> <span style="color: red">Type</span><span style="color: blue">=&quot;Int32&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Parameter</span> <span style="color: red">DefaultValue</span><span style="color: blue">=&quot;large.bmp&quot;</span> <span style="color: red">Name</span><span style="color: blue">=&quot;fileName&quot;</span> <span style="color: red">Type</span><span style="color: blue">=&quot;String&quot;</span> <span style="color: blue">/&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">SelectParameters</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ObjectDataSource</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">&lt;/</span><span style="color: maroon">div</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">&lt;/</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Content</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;</p>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/09/04/iisaspnetperf/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Fourth MSDN Article Published! &quot;Adding Personalization with Profiles to the ObjectDataSource&quot;</title>
		<link>http://peterkellner.net/2006/09/04/addprofiletoods/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=addprofiletoods</link>
		<comments>http://peterkellner.net/2006/09/04/addprofiletoods/#comments</comments>
		<pubDate>Mon, 04 Sep 2006 18:55:33 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2006/09/04/addprofiletoods/</guid>
		<description><![CDATA[This article explains how the encapsulation of Membership can be extended to include Profile (personalization) information for users. The designers of Membership included a very basic set of attributes to associate with Members (logged in users).]]></description>
			<content:encoded><![CDATA[<p>Microsoft just published my fourth article. This one is titled: &quot;<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditorwithprofile.asp">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 4: Adding Personalization with Profiles to the ObjectDataSource</a>&quot;.</p>
<p>You can find it on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditorwithprofile.asp">MSDN here</a>, or on <a href="http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/">my blog here</a>.</p>
<p>Here is the introduction.</p>
<p> <span id="more-31"></span><br />
<h2>Introduction</h2>
<p>This article extends one of the web pages developed in <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Part II of this series</a> using Microsoft’s Profile feature. In Part II, the Membership API was encapsulated in an ObjectDataSource. This allowed the developer to have a drop in web page for the web site administrator to use in an web site project for editing membership. This tools allowed for similar capability to the the web site manager tool included in Visual Studio 2005 (VS2005). It is necessary because using that web configuration tool included with VS2005 is problematic and should not be used in a production web site.</p>
<p>This article explains how the encapsulation of Membership can be extended to include Profile (personalization) information for users. The designers of Membership included a very basic set of attributes to associate with Members (logged in users). The Profile API provided by Microsoft allows for additional information to be attached to each member. Typically, this information would include things like: first name, last name, home address, favorite color schemes or anything else the developer may want to associate with a logged in member. By personalizing the site to the member logged in, it likely increases the chance the user will return and be more comfortable while visiting.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/09/04/addprofiletoods/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Third Article Published on MSDN! ASP.NET 2.0, Membership Meets Atlas</title>
		<link>http://peterkellner.net/2006/08/02/third-article-published-on-msdn-aspnet-20-membership-meets-atlas/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=third-article-published-on-msdn-aspnet-20-membership-meets-atlas</link>
		<comments>http://peterkellner.net/2006/08/02/third-article-published-on-msdn-aspnet-20-membership-meets-atlas/#comments</comments>
		<pubDate>Wed, 02 Aug 2006 22:30:55 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Atlas/AJAX]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[MSDN Articles]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=41</guid>
		<description><![CDATA[Microsoft published my third article in a series on how to use Membership in ASP.NET 2.0 with an ObjectDataSource.  That is, extending Membership into three tiers.  This article takes what was developed in article two and adds Atlas extensions to make it work even better.  The Article on MSDN uses the March CTP (Community Technology Preview).  There is an update on my blog as well as a download to make it work correctly with the June CTP.]]></description>
			<content:encoded><![CDATA[<p>Microsoft just published my third article. This one is titled: &quot;Member/Role Management with IIS, Part 3: AJAX Enhancements with Microsoft’s Atlas&quot;.</p>
<p>You can find it on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditoratlas.asp">MSDN here</a>, or on <a href="http://peterkellner.net/?p=1">my blog here</a>.</p>
<p>Here is the introduction.</p>
<h2>Introduction</h2>
<p>This article extends one of the web pages developed in Part II of this series using Microsoft’s implementation of AJAX called Atlas. It utilized two techniques for reducing web server traffic to the browser to enhance the users web experience. The first technique uses the UpdatePanel tags to limit the refreshed area of the web page to limited areas and the second has to do with implementing some javascript using Atlas techniques so that the web page is updated on every key stroke in a textbox. A user list is displayed based on what is actively typed into this textbox. After reading this article the developer will be able to implement AJAX (Microsoft’s implementation Atlas) in their own application.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/08/02/third-article-published-on-msdn-aspnet-20-membership-meets-atlas/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Inserting Programmatically with ObjectDataSource in ASP.NET 2.0</title>
		<link>http://peterkellner.net/2006/06/07/inserting-programmatically-with-objectdatasource-in-aspnet-20/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inserting-programmatically-with-objectdatasource-in-aspnet-20</link>
		<comments>http://peterkellner.net/2006/06/07/inserting-programmatically-with-objectdatasource-in-aspnet-20/#comments</comments>
		<pubDate>Wed, 07 Jun 2006 20:21:02 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=37</guid>
		<description><![CDATA[( ObjectDataSource1.Insert(); )
ObjectDataSource&#8217;s are great for building your own middle tier between your aspx web page and your database (or any other datastore for that matter). By binding the datasource to a databound server control like detailsview, you auto-magically get the insert behavior you are looking for. If however, you just just want to insert [...]]]></description>
			<content:encoded><![CDATA[<h2>( ObjectDataSource1.Insert(); )</h2>
<p>ObjectDataSource&#8217;s are great for building your own middle tier between your aspx web page and your database (or any other datastore for that matter). By binding the datasource to a databound server control like detailsview, you auto-magically get the insert behavior you are looking for. If however, you just just want to insert to the ObjectDataSource you have included on your aspx page without using a databound control, you don&#8217;t have a lot of fancy footwork to do. All you have to do is reference the insert parameter by name (or index offset) and assign it directly.</p>
<p> <span id="more-23"></span>
<p>Below is an example of how to insert a Role into Membership using the ObjectDataSource developed in a my previous MSDN article <a href="http://peterkellner.net/?p=24">Microsoft ASP.NET 2.0 Member/Role Management with IIS     <br />Part 2: Implementation</a>.</p>
<p> <!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode"><span class="kwrd">&lt;</span> %@ Page Language=&quot;C#&quot; <span class="asp">%&gt;</span>
<span class="kwrd">&lt;</span> !DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;<span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">protected</span> <span class="kwrd">void</span> Button1_Click(<span class="kwrd">object</span> sender, EventArgs e)
{
  ObjectDataSource1.InsertParameters[<span class="str">&quot;roleName&quot;</span>].DefaultValue =
    TextBoxRole.Text;
  ObjectDataSource1.Insert();
}
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>AddRoleWithODS.aspx<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">=&quot;form1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">: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>
    <span class="attr">InsertMethod</span><span class="kwrd">=&quot;Insert&quot;</span>
    <span class="attr">SelectMethod</span><span class="kwrd">=&quot;GetRoles&quot;</span>
    <span class="attr">TypeName</span><span class="kwrd">=&quot;MembershipUtilities.RoleDataObject&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">insertparameters</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr"> <img src='http://PetersBlogCDN.s3.amazonaws.com/wp/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> arameter</span> <span class="attr">Name</span><span class="kwrd">=&quot;roleName&quot;</span> <span class="attr">Type</span><span class="kwrd">=&quot;String&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">insertparameters</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Button</span> <span class="attr">ID</span><span class="kwrd">=&quot;Button1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Add Role&quot;</span>
    <span class="attr">OnClick</span><span class="kwrd">=&quot;Button1_Click&quot;</span> <span class="kwrd">/&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">=&quot;TextBoxRole&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<p>If you do not want to declaratively define the ObjectDataSource and just want to use it directly, you can do that also. You simply reference the ObjectDataSource by Type and call its insert method. An example of that is below.</p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> MembershipUtilities;

<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Default3 : Page
{
  <span class="kwrd">protected</span> <span class="kwrd">void</span> Button1_Click(<span class="kwrd">object</span> sender, EventArgs e)
  {
    RoleDataObject.Insert(TextBox1.Text);
  }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/06/07/inserting-programmatically-with-objectdatasource-in-aspnet-20/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Adding Personalization via Profiles to the ObjectDataSource in ASP.NET 2.0</title>
		<link>http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20</link>
		<comments>http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/#comments</comments>
		<pubDate>Tue, 14 Mar 2006 00:33:03 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[MSDN Articles]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=29</guid>
		<description><![CDATA[<p>This article explains the mechanics involved in extending the ObjectDataSource (developed in the previous article in this <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">MSDN Membership Security Series</a>) to handle personalization information using the ASP.NET 2.0 custom provider facility. Then, it goes on to explains some fancy tricks you can do with this ObjectDataSource to make accessing membership even easier. Finally it presents a <a href="http://painfreeods.peterkellner.net/Default.aspx">free tool available on the web</a> that lets you cut and paste part of your web.config file into a web page and out comes a ready-to-compile C-Sharp ObjectDataSource.</p>]]></description>
			<content:encoded><![CDATA[<p>Also published on Microsoft’s MSDN Network at <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/membershipeditorwithprofile.asp">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 4: Adding Personalization with Profiles to the ObjectDataSource</a></p>
<p>Applies to:</p>
<ul>
<li>Microsoft ASP.NET 2.0 </li>
<li>Microsoft Visual Studio 2005 </li>
<li>Microsoft Internet Information Services </li>
</ul>
<p><a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultWithProfile.aspx"></a></p>
<p> <span id="more-20"></span>
<p><a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultWithProfile.aspx">Run Live Demonstration Of Personalization in Membership Technology</a></p>
<p><a href="http://painfreeods.peterkellner.net/">Go to the Web Site to Create Your Own ObjectDataSource From Your Own Web.Config</a></p>
<p><a href="http://download.microsoft.com/download/3/6/5/36559e56-c23f-47cc-9442-a160b3f1b99c/MembershipEditorWithProfile.msi">Click Here for Source Code Associated With This Article</a></p>
<p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 2: Implementation</a><span></span> </p>
<hr  ="&lt;hr" />
<h4>Contents</h4>
<p> <a href="#Introduction">Introduction</a>   <br /><a href="#Background">Background</a>   <br /><a href="#Why">Why Do We Need This?</a>   <br /><a href="#Adding">Adding Profile Information to the ObjectDataSource</a>   <br /><a href="#Using">Using the Profile Generating Website</a>   <br /><a href="#Build">Build A Simple Web Page</a>   <br /><a href="#Conclusions">Conclusions</a>   <br /> <br />
<h2 id="Introduction">Introduction</h2>
<p>This article extends one of the web pages developed in <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Part II of this series</a> using Microsoft&#8217;s Profile feature. In Part II, the Membership API was encapsulated in an ObjectDataSource. This allowed the developer to have a drop in web page for the web site administrator to use in an web site project for editing membership. This tools allowed for similar capability to the the web site manager tool included in Visual Studio 2005 (VS2005). It is necessary because using that web configuration tool included with VS2005 is problematic and should not be used in a production web site.</p>
<p>This article explains how the encapsulation of Membership can be extended to include Profile (personalization) information for users. The designers of Membership included a very basic set of attributes to associate with Members (logged in users). The Profile API provided by Microsoft allows for additional information to be attached to each member. Typically, this information would include things like: first name, last name, home address, favorite color schemes or anything else the developer may want to associate with a logged in member. By personalizing the site to the member logged in, it likely increases the chance the user will return and be more comfortable while visiting.</p>
<h2>Background</h2>
<p>ASP.NET has done an outstanding job of making the profile information associated with a logged in user very easy to access programmatically. They have done this by using their Provider technology to create a typed class that the developer can access with intellisense property values. What does this mean? This means that the profile information is declaratively defined as XML in the web.config file. The example below shows the lines that have been added to the &lt;system.web&gt; section of the web.config.</p>
<p> 
<pre class="csharpcode"> <span class="kwrd">&lt;</span><span class="html">system</span> .<span class="attr">web</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">profile</span> <span class="attr">defaultProvider</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;AspNetSqlProfileProvider&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span>
       <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Profile.SqlProfileProvider&quot;</span>
       <span class="attr">connectionStringName</span><span class="kwrd">=&quot;LocalSqlServer&quot;</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">properties</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;FirstName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;LastName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;AdvancedMode&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;bool&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">group</span> <span class="attr">name</span><span class="kwrd">=&quot;Address&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Street&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;City&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;State&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Zip&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span><span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">group</span><span class="kwrd">&gt;</span>    <span class="kwrd">&lt;/</span><span class="html">properties</span><span class="kwrd">&gt;</span>  <span class="kwrd">&lt;/</span><span class="html">profile</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system</span><span class="kwrd">&gt;</span></pre>
<p></p>
<p>These new properties defined by Microsoft can be accessed in C# at run time very simply. Below are a few lines of code showing how this can be done in a typical codebehind page. These lines of code are taken from the button update event on the page UpdateProfileSimple.aspx included in the download associated with this article.</p>
<p></p>
<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonUpdate_Click(<span class="kwrd">object</span> sender,
    EventArgs e)
{
  Profile.FirstName = TextBoxFirstName.Text;
  Profile.LastName = TextBoxLastName.Text;
  Profile.Save();
}</pre>
<p></p>
<p>Profile is available everywhere because it is a static class generated from the Web.Config section shown above. Because it is an actual class, the properties FirstName and LastName are available from VS2005&#8242;s intellisense and are type safe. No incorrectly typing them and getting syntax errors.</p>
<p>In the simple example below (UpdateProfileSimple.aspx), it is necessary to first pre load the textboxes when the user logs in. This can be done in the pageload event as follows.</p>
<p></p>
<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
{
  <span class="rem">// Only allow for profile update when a user is logged in</span>
  MembershipUser mu = Membership.GetUser();
  <span class="kwrd">if</span> (mu == <span class="kwrd">null</span>)
  {
    ButtonUpdate.Enabled = <span class="kwrd">false</span>;
  }
  <span class="kwrd">else</span>
  {
    <span class="kwrd">if</span> (!IsPostBack)
    {
      TextBoxFirstName.Text = Profile.FirstName;
      TextBoxLastName.Text = Profile.LastName;
    }
  }
}</pre>
<p></p>
<p>There are a couple things to notice in the above page_load event. First, if no user is logged in, the update button is disabled. This is because it would be meaningless to press the update button if there was no current user to update. It is important to mention that this article does not address dealing with anonymous users. That is a whole different topic. Very interesting, but beyond the scope of this article. Also notice that the first and last names are only loaded when the page is not a postback. That means that only the first time this page is loaded will the data will be loaded from the Profile datastore. After the first time, the data is stored in the page&#8217;s viewstate and no longer will have to be retrieved from the static Profile class. This is important to note because each time a profile property is accessed, a round trip to the membership database occurs. This is the reason using the Profile classes are often referred to as chatty with the database. Something to think about, and keep in mind when designing your application.</p>
<p>There are several good articles that go into more detail on using the profile provider. <a href="http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx">Scott Gu posts in his blog</a> an excellent how to guide that steps you through creating basic Membership in a web application including customized Profile information. A good one in MSDN is <a href="http://msdn.net/msdnmag/issues/05/10/CuttingEdge/">Personalization and User Profiles in ASP.NET 2.0 by Dino Esposito</a>. Another one of my favorites is <a href="http://www.odetocode.com/Articles/440.aspx">Profiles in ASP.NET 2.0 by Scott Allen</a>.</p>
<h2 id="#Why">Why Do We Need This? </h2>
<p>The questions comes up, why do we need an ObjectDataSource that encapsulates our Profile information? The answer is this. Even though ASP.NET does a wonderful job of giving us programmatic access to the Profile class it does not gives a simple way to view or update this data by binding it directly to any controls like gridview or detailsview. Joshua Flanagan wrote a very nice tool called <a href="http://peterkellner.net/download-manager/">ProfileView</a> that you can see on his blog. Basically, he wrote an ASP.NET 2.0 server control that enables users to view and/or edit the Profile data. It does this using reflection at runtime to figure out what the profile information is, then it shows it.</p>
<p>The ObjectDataSource allows you at design time to make the presentation layer look exactly as you like. It also allows for viewing multiple members profiles at the same time. Take a look at the screen shot below to see what a gridview looks like using on ObjectDataSource generated using this technology. Also, you can <a href="http://livedemos.peterkellner.net/AJAXDemo/DefaultWithProfile.aspx">play with it live right here</a>.</p>
<table border="0" cellpadding="10" width="200">
<tbody>
<tr>
<td><a href="http://peterkellner.net/images/MembershipProvider/membership.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/membership_t.jpg" width="341" height="388" /></a></td>
<td><img src="/images/MembershipProvider/membership_namesonly.jpg" /></td>
</tr>
</tbody>
</table>
<p>At first glance, this is identical the screen developed in<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp"> Part 2 of this series</a>. If you look closer however (or at the picture to the right of the first one), you&#8217;ll notice that there are two new columns. First Name and Last Name. Both of these columns have data retrieved from the Membership Profile data provider we have been discussing. In the next section the details of what changes to the ObjectDataSource in the previous article have been made to allow this to happen. Something very important to note however, is that since the ObjectDataSource is basically a static class, the profile information in that ObjectDataSource will not automatically change when the web.config is changed (unlike <a href="http://flimflan.com/blog/ProfileView.aspx">Joshua Flanagan&#8217;s solution</a> which will change).</p>
<h2 id="Adding">Adding Profile Information to the ObjectDataSource</h2>
<p>As was mentioned earlier, the ObjectDataSource developed here is 100% based on the one developed in <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.asp">Part II of this MSDN series, Implementation</a>. The discussion here assumes all the previous code is understood and only explains the additions to support the Profile feature. All the code described here is what gets generated by the <a href="http://painfreeods.peterkellner.net/">ObjectDataSource generator on Peter Kellner&#8217;s Blog</a> (this tool is discussed in greater detail in the next major section of this article). In this section we go through the details of what gets added. In the next section it is shown how the steps to generating the source described here from an existing web.config file.</p>
<h3>Changing Class Names </h3>
<p>Since it&#8217;s possible the ObjectDataSource geneated here may be used in the same project as the one provided with Part 2 of this series, all the public names have been changed to avoid naming conflicts. For example, the class name MembershipUserODS has been renamed to MembershipUserAndProfileODS. The RoleData class has been renamed RoleDataForMP and the MemberhipUserWrapper class has been renamed MembershipUserWrapperForMP (MP standing for MembershipProfile).</p>
<h3>The Insert Method</h3>
<p>The method signature of Insert now contains all the names of the Profile properties. In addition to Membership.CreateUser being called, the Profile properties must be saves also with the Profile.Save() method. Below is the complete Insert method for an example set of profile properties (profile properties are stored in the web.config file and will likely be different for each asp.net web application).</p>
<p></p>
<pre class="csharpcode">[DataObjectMethod(DataObjectMethodType.Insert, <span class="kwrd">true</span>)]
<span class="kwrd">public</span> <span class="kwrd">void</span> Insert(<span class="kwrd">string</span> userName, <span class="kwrd">bool</span> isApproved,
    <span class="kwrd">string</span> comment, DateTime lastLockoutDate,
    DateTime creationDate,<span class="kwrd">string</span> email,
    DateTime lastActivityDate, <span class="kwrd">string</span> providerName,
    <span class="kwrd">bool</span> isLockedOut,DateTime lastLoginDate,
    <span class="kwrd">bool</span> isOnline, <span class="kwrd">string</span> passwordQuestion,
    DateTime lastPasswordChangedDate, <span class="kwrd">string</span> password,
    <span class="kwrd">string</span> passwordAnswer, <span class="kwrd">string</span> firstName,
    <span class="kwrd">string</span> lastName, <span class="kwrd">bool</span> advancedMode,
    <span class="kwrd">string</span> address_Street, <span class="kwrd">string</span> address_City,
    <span class="kwrd">string</span> address_State, <span class="kwrd">string</span> address_Zip
    )
{

    MembershipCreateStatus status;
    Membership.CreateUser(userName, password, email,
        passwordQuestion, passwordAnswer,
        isApproved, <span class="kwrd">out</span> status);

    <span class="kwrd">if</span> (status != MembershipCreateStatus.Success)
    {
     <span class="kwrd">throw</span> <span class="kwrd">new</span> ApplicationException(status.ToString());
    }

    MembershipUser mu = Membership.GetUser(userName);
    mu.Comment = comment;
    Membership.UpdateUser(mu);
    ProfileCommon pc =
     (ProfileCommon)ProfileBase.Create
        (mu.UserName, <span class="kwrd">true</span>);
    pc.FirstName = firstName;
    pc.LastName = lastName;
    pc.AdvancedMode = advancedMode;
    pc.Address.Street = address_Street;
    pc.Address.City = address_City;
    pc.Address.State = address_State;
    pc.Address.Zip = address_Zip;
    pc.Save();
}</pre>
<p></p>
<p>Something also to take note of is the the variable names are constructed with an underscore because variable names with periods would not work. Notice in particular the properties that are nested such as address_state. This refers to the Profile property pc.Address.State.</p>
<h3>The Delete Method</h3>
<p>The delete method has no changes. This is because the membership class takes care of removing all profile information when Membership.DeleteUser() is invoked.</p>
<h3>The Update Method</h3>
<p>The Update method is changed. To the parameter list is added all the parameters representing properties. Then, in the update method itself the profile information is update after the Membership is updated. below is a portion of the code for this using the example properties.</p>
<p></p>
<pre class="csharpcode">ProfileCommon pc = (ProfileCommon)ProfileBase.
      Create(mu.UserName, <span class="kwrd">true</span>);
    pc.FirstName = firstName;
    pc.LastName = lastName;
    pc.AdvancedMode = advancedMode;
    pc.Address.Street = address_Street;
    pc.Address.City = address_City;
    pc.Address.State = address_State;
    pc.Address.Zip = address_Zip;
    pc.Save();</pre>
<p></p>
<h3>The Get (Select) Methods </h3>
<p>Just like in Part 2 of this series, there are several Get Methods provided. No additional get methods are added, however now, because of the addition of the Profile properties, the Get Method&#8217;s return profile properties include Membership Properties as well as Profile properties. This is handled by first retrieving the Membership data with GetUser or GetUsers methods, then adding the additional properties from the profile to the Generic list which will get returned. The critical section of code that does this is next.</p>
<p></p>
<pre class="csharpcode">MembershipUserCollection muc = Membership.GetAllUsers();
<span class="kwrd">foreach</span> (MembershipUser mu <span class="kwrd">in</span> muc)
{
 <span class="kwrd">if</span> ((returnAllApprovedUsers==<span class="kwrd">true</span> &amp;amp;&amp;amp; mu.IsApproved==<span class="kwrd">true</span>) ||
 (returnAllNotApprovedUsers==<span class="kwrd">true</span> &amp;amp;&amp;amp; mu.IsApproved==<span class="kwrd">false</span>))
 {
    MembershipUserWrapperForMP md =
      <span class="kwrd">new</span> MembershipUserWrapperForMP(mu);
    ProfileCommon pc = (ProfileCommon)ProfileBase.Create
      (mu.UserName, <span class="kwrd">true</span>);
    md.FirstName = pc.FirstName;
    md.LastName = pc.LastName;
    md.AdvancedMode = pc.AdvancedMode;
    md.Address_Street = pc.Address.Street;
    md.Address_City = pc.Address.City;
    md.Address_State = pc.Address.State;
    md.Address_Zip = pc.Address.Zip;
    memberList.Add(md);
 }
}</pre>
<p></p>
<h3>Sorting Support </h3>
<p>Sorting the ObjectDataSource&#8217;s columns is also supported. Just as in Membership Part 2, this is supported using anonymous delegates. Basically, a comparater method is created with an anonymous delegate that takes two parameters. The left and right hand side of a sort operation. Then, using this comparater, the generic List is sorted before being returned to the caller. This very clever construct was inspired by <a href="http://blogs.tedneward.com">Ted Neward </a>at a Code Camp in Portland.</p>
<p>Just like the MembershipUser properties, Profile properties are handled the same way so that those values can be sorted in a GridView by clicking on the column headers. Below is the creation of one comparater method.</p>
<p></p>
<pre class="csharpcode"><span class="kwrd">switch</span> (sortDataBase)
{
  <span class="kwrd">case</span> &amp;quot;FirstName&amp;quot;:
    comparison = <span class="kwrd">new</span>
      Comparison&lt;membershipuserwrapperformp&gt;(
       <span class="kwrd">delegate</span>(MembershipUserWrapperForMP lhs,
            MembershipUserWrapperForMP rhs)
       {
           <span class="kwrd">return</span> lhs.FirstName.CompareTo(
              rhs.FirstName);
       }
     );
    <span class="kwrd">break</span>;&lt;/membershipuserwrapperformp&gt;</pre>
<p></p>
<h3>The Class associated with the Generic List </h3>
<p>The final piece of code that has to be extended is the Class that is returned from the Get methods. That is the generic list which is declared as follows.</p>
<p></p>
<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
{
  <span class="rem">// Only allow for profile update when a user is logged in</span>
  MembershipUser mu = Membership.GetUser();
  <span class="kwrd">if</span> (mu == <span class="kwrd">null</span>)
  {
    ButtonUpdate.Enabled = <span class="kwrd">false</span>;
  }
  <span class="kwrd">else</span>
  {
    <span class="kwrd">if</span> (!IsPostBack)
    {
      TextBoxFirstName.Text = Profile.FirstName;
      TextBoxLastName.Text = Profile.LastName;
    }
  }
}</pre>
<p></p>
<h3>One Final Trick on Using the ObjectDataSource </h3>
<p>ObjectDataSource&#8217;s are great for using with databound ASP.NET&#8217;s controls such as GridView and DetailsView. They are wired such that the get methods, update, delete and insert line up perfectly with what those controls are looking for. However, the ODS&#8217;s can be used directly without having a presentation style control associated with them. For example, the Insert method associated with adding a new member in the included code from the asp.net page MembershipWithProfile.aspx uses the ObjectDataSource to insert even though it is not bound to any control on the page. The data it is entering is coming from TextBox&#8217;s in a table. Below is the Insert code used. Notice how straight forward it is to use compared do creating an inserter and doing all the ADO without this class.</p>
<p></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonNewUser_Click(<span class="kwrd">object</span> sender, EventArgs e)
{

    MembershipUtilities.MembershipUserAndProfileODS
      membershipUserAndProfileODS =
        <span class="kwrd">new</span> MembershipUserAndProfileODS();

    membershipUserAndProfileODS.Insert(
        TextBoxUserName.Text,
        CheckboxApproval.Checked,
        <span class="kwrd">string</span>.Empty,
        DateTime.Now,
        DateTime.Now,
        TextBoxEmail.Text,
        DateTime.Now,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">false</span>,
        DateTime.Now,
        <span class="kwrd">false</span>,
        TextBoxPasswordQuestion.Text,
        DateTime.Now,
        TextBoxPassword.Text,
        TextBoxPasswordAnswer.Text,
        TextBoxFirstName.Text,
        TextBoxLastName.Text,
        <span class="kwrd">false</span>,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">string</span>.Empty,
        <span class="kwrd">string</span>.Empty);

    GridViewMemberUser.DataBind();
    TextBoxUserName.Text = <span class="kwrd">string</span>.Empty;
    TextBoxFirstName.Text = <span class="kwrd">string</span>.Empty;
    TextBoxLastName.Text = <span class="kwrd">string</span>.Empty;
    TextBoxPassword.Text = <span class="kwrd">string</span>.Empty;
    TextBoxEmail.Text = <span class="kwrd">string</span>.Empty;
    TextBoxPasswordAnswer.Text = <span class="kwrd">string</span>.Empty;
    TextBoxPasswordQuestion.Text = <span class="kwrd">string</span>.Empty;
    CheckboxApproval.Checked = <span class="kwrd">false</span>;
}</pre>
<p></p>
<p>Because this is an actual class with properties, using the ObjectDataSource class is type safe. For example, in the code below, the user may want to count how many zipcodes in the membership database that begin with 9. Here is the code to do it. Notice how Address_Zip is used in a type safe way.</p>
<p></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonZipCount_Click
    (<span class="kwrd">object</span> sender, EventArgs e)
{
    MembershipUtilities.MembershipUserAndProfileODS
        membershipUserAndProfileODS =
        <span class="kwrd">new</span> MembershipUserAndProfileODS();

    List&lt;membershipuserwrapperformp&gt; li =
        membershipUserAndProfileODS.GetMembers
        (<span class="kwrd">string</span>.Empty);

    <span class="kwrd">int</span> count = 0;
    <span class="kwrd">foreach</span> (MembershipUserWrapperForMP mu <span class="kwrd">in</span> li)
    {
        <span class="kwrd">if</span> (mu.Address_Zip.StartsWith(&amp;quot;9&amp;quot;))
        {
            count++;
        }
    }
}&lt;/membershipuserwrapperformp&gt;</pre>
<p></p>
<h2 id="Using">Using the Profile Generating Website </h2>
<p>All the changes listed in the previous section could be done by hand, however this would be very tedious. To make this process much easier, a code generator has been developed which takes as input the applications web.config file&#8217;s &lt;System.Web&gt; section. The idea is to cut this out of the web.config file and paste it into the web page which will generate the code for you. Below is a screen show of what the web page looks like. When you get to this page, you must first click on the button in the right column labeled &quot;Click Here to Begin&quot;.</p>
<p>Here is the URL: <a href="http://painfreeods.peterkellner.net/">http://painfreeods.peterkellner.net/</a></p>
<p>&#160;<a href="http://peterkellner.net/images/MembershipProvider/ProfileGenPage.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/ProfileGenPage_t.jpg" /></a></p>
<p>The XML which is pasted into the multi line orange textbox is as follows (you should paste your own in here).</p>
<p></p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">system</span>  .<span class="attr">web</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">profile</span> <span class="attr">defaultprovider</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">providers</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">remove</span> <span class="attr">name</span><span class="kwrd">=&quot;AspNetSqlProfileProvider&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;SqlProfileProvider&quot;</span> <span class="attr">connectionstringname</span><span class="kwrd">=&quot;LocalSqlServer&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;System.Web.Profile.SqlProfileProvider&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">providers</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">properties</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;FirstName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;LastName&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;AdvancedMode&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;bool&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">group</span> <span class="attr">name</span><span class="kwrd">=&quot;Address&quot;</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Street&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;City&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;State&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Zip&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;string&quot;</span> <span class="kwrd">/&gt;</span>
      <span class="kwrd">&lt;/</span><span class="html">group</span><span class="kwrd">&gt;</span>    <span class="kwrd">&lt;/</span><span class="html">properties</span><span class="kwrd">&gt;</span>  <span class="kwrd">&lt;/</span><span class="html">profile</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">system</span><span class="kwrd">&gt;</span></pre>
<p></p>
<p>Now, if the &quot;Show Generated C#&quot; button is pressed, the complete ObjectDataSource will be created. This code can then be cut and pasted into the App_Code directory of the web project. Here is what the screen looks like.</p>
<p><a href="http://peterkellner.net/images/MembershipProvider/ProfileGenSrc.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/ProfileGenSrc_t.jpg" /></a></p>
<p>There are some limitations to this code generation technology. First is that there can only be one level of nesting. That is, there can be no groups of groups. Just one level of grouping is allowed as is shown here. It is OK to have multiple groups, just not nested. Another limitation is the type associated with the name must be a C# type. That is, string, bool,DateTime,etc. The final limitation (known about) is that it can not handle Array or Collection type properties. All properties must be single valued.</p>
<p>At this point, error checking is minimal so if the limitations are exceeded, something will likely come out but it may not be what was desired.</p>
<h2 id="Build">Build A Simple Web Page</h2>
<p>Now that the C# class has been generated, the next steps are very straight forward. For those who have not built a GridView based on an ObjectDataSource, here is a pictorial step by step of the 9 things needed to do to have a very simple gridview control in under 5 minutes.</p>
<table border="0" cellpadding="2" width="694">
<caption>Building a Web Page From Scratch<br />
    <br /></caption>
<tbody>
<tr>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step1.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step1_t.jpg" width="250" height="186" /></a></p>
<p>1. Add a New Web Page to the Project</p>
</td>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step2.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step2_t.jpg" width="250" height="179" /></a></p>
<p>2. Choose Web Page and Name it</p>
</td>
</tr>
<tr>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step3.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step3_t.jpg" width="250" height="206" /></a></p>
<p>3. Add a GridView and an ObjectDataSource. Associate them</p>
</td>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step4.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step4_t.jpg" /></a></p>
<p>4. Configure the ObjectDataSource by Assigning the Class</p>
</td>
</tr>
<tr>
<td>
<p>&#160;</p>
<p><a href="http://peterkellner.net/images/MembershipProvider/step5.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step5_t.jpg" width="250" height="174" /></a></p>
<p>5. Choose the Get Method (Use Default)</p>
</td>
<td>
<p>&#160;</p>
<p><a href="http://peterkellner.net/images/MembershipProvider/step6.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step6_t.jpg" width="250" height="174" /></a></p>
<p>6. Choose the Update Method (Use Default)</p>
</td>
</tr>
<tr>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step7.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step7_t.jpg" width="250" height="174" /></a></p>
<p>7. Choose the Insert Method (Choose Default)</p>
</td>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step8.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step8_t.jpg" width="250" height="174" /></a></p>
<p>8. Choose the Delete Method (Choose Default)</p>
</td>
</tr>
<tr>
<td>
<p><a href="http://peterkellner.net/images/MembershipProvider/step9.jpg"><img border="0" src="http://peterkellner.net/images/MembershipProvider/step9_t.jpg" width="250" height="154" /></a></p>
<p>9. Run it! (OK, had to enable edit and delete on Gridview. No more boxes left)</p>
</td>
<td>&#160;</td>
</tr>
</tbody>
</table>
<p>The code in the associated source to this article has a web apge ( MembershipWithProfile.aspx) which is very similar to what is done here.</p>
<h2 id="Conclusions">Conclusions</h2>
<p>Profiles are a very powerful way to store information about Membership. It&#8217;s powerful in that with very little coding, lots of additional information about logged in users is available. With this tool, there is now a better way to organize this information and maintain it. Briefly mentioned earlier were the performance implications of using Profile information. It is important to understand what his happening under the covers when this technology is used. As long there is an understanding of what is happening and it is acceptable in the web application being developed, this is a wonderful technology.</p>
<p>Finally, as a plug to the technology that was used in this free ObjectDataSource creator, the Pain Free ObjectDataSource Creator, available through subscription on this blog, lets the developer generate very flexible ObjectDataSource&#8217;s to access database information in SqlServer, MySql and Oracle. Unlike the Profile ODS generator in this article, the ODS generator for databases gives you a large amount of flexibility. An infinite number of getter methods, updaters and inserters can be defined. It works with views, and also stored procedures. Any questions on the Pain Free ODS Generator, <a href="http://peterkellner.net/contact/">click here</a>.</p>
<p>Thanks for reading, and best of luck with your coding projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/03/13/adding-personalization-via-profiles-to-the-objectdatasource-in-aspnet-20/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Membership Management Newly Styled GridView</title>
		<link>http://peterkellner.net/2006/01/27/membership-management-newly-styled-gridview/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=membership-management-newly-styled-gridview</link>
		<comments>http://peterkellner.net/2006/01/27/membership-management-newly-styled-gridview/#comments</comments>
		<pubDate>Fri, 27 Jan 2006 17:46:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=27</guid>
		<description><![CDATA[Mikhail Lukyanau has been kind enough to provide a redesigned version of the membership.aspx page]]></description>
			<content:encoded><![CDATA[<p><body></p>
<p class="style4">Mikhail Lukyanau has been kind enough to provide a redesigned version of the membership.aspx page. The source file for this can be downloaded at <a href="http://peterkellner.net/zdm_1_2/index.php?file=7">(Download New File)</a>. Below is a screen shot of this new look. </p>
<p class="style4"><a href="http://peterkellner.net/images/MSDN_Membership/Membership1aspx.jpg"><img src="http://peterkellner.net/images/MSDN_Membership/Membership1aspx_t.jpg" alt="" width="400" height="300" border="0" longdesc="http://peterkellner.net/images/MSDN_Membership/Membership1aspx.jpg" /></a></p>
<p class="style4">Figure 1 &#8211; Updated Design for Membership.aspx By Mikhail Lukyanau</p>
<p class="style4">&nbsp; </p>
<p></body></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/01/27/membership-management-newly-styled-gridview/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Using Membeship ObjectDataSource For Returning ProviderUserKey (ForeignKey Use)</title>
		<link>http://peterkellner.net/2006/01/10/using-membeship-objectdatasource-for-returning-provideruserkey/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-membeship-objectdatasource-for-returning-provideruserkey</link>
		<comments>http://peterkellner.net/2006/01/10/using-membeship-objectdatasource-for-returning-provideruserkey/#comments</comments>
		<pubDate>Tue, 10 Jan 2006 16:54:53 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[Membership]]></category>
		<category><![CDATA[ObjectDataSource]]></category>

		<guid isPermaLink="false">http://peterkellner.net/archives/2006/01/10/26/</guid>
		<description><![CDATA[<p>This article gives an example of how to modify the Object DataSource in the previous article (<a href="http://peterkellner.net/archives/2006/01/09/24/">Microsoft ASP.NET 2.0 Member/Role Management with IIS<br />
Part 1: Security and   Configuration Overview </a> ) to return a ProviderUserKey which can then be used as a foreign key into the developer's own data tables.
</p><p></p>]]></description>
			<content:encoded><![CDATA[<p>I was recently asked how to use the Membership Data Object to return the unique ProviderKey generated by the Membership object. This may be necessary if want to associate the membership data with an existing table. That is, add a foreign key &quot;ProviderUserKey&quot; to another table so you can track an existing user to your current database without getting involved in extending the base provider. You can of course extend the existing provider to include other fields, but in general, you probably are better off maintaining your own tables rather than extending the provider model. Peter Dawson does an excellent job of explaining and showing how to extend the Membership Provider in his article <a href="http://www.theserverside.net/articles/showarticle.tss?id=CreatingProfileProvider">Creating a Custom ASP.NET Provider. </a>(published on theserverside.net)</p>
<p> <span id="more-16"></span>
<p>So, back to what needs to be done to use my Membership ObjectDataClass (<a title="View Details: Microsoft ASP.NET 2.0 Member/Role Management with IIS&lt;br/&gt;Part 2: Implementation" href="http://peterkellner.net/archives/2006/01/09/24/" rel="bookmark">Part 2: Implementation&quot; href=&quot;http://peterkellner.net/archives/2006/01/09/24/&quot; rel=bookmark&gt;Microsoft ASP.NET 2.0 Member/Role Management with IIS</a>
<p>Part 2: Implementation</p>
<p> ). First thing is you need to add another insert method to the class. This method takes just a few parameters and returns as out parameters both the status of the insert as well as the providerUserKey as a string.</p>
<p> 
<pre class="csharpcode">
[DataObjectMethod(DataObjectMethodType.Insert, <span class="kwrd">false</span>)]
<span class="kwrd">static</span> <span class="kwrd">public</span> <span class="kwrd">void</span> Insert(<span class="kwrd">string</span> userName,
    <span class="kwrd">bool</span> isApproved,
    <span class="kwrd">string</span> email,
    <span class="kwrd">string</span> passwordQuestion,
    <span class="kwrd">string</span> password,
    <span class="kwrd">string</span> passwordAnswer,
    <span class="kwrd">out</span> MembershipCreateStatus membershipCreateStatus,
    <span class="kwrd">out</span> <span class="kwrd">string</span> providerIdKeyString)
{
    MembershipUser muNew = Membership.CreateUser(userName,
        password, email, passwordQuestion, passwordAnswer,
        isApproved,<span class="kwrd">out</span> membershipCreateStatus);
    <span class="kwrd">if</span> (membershipCreateStatus ==
        MembershipCreateStatus.Success)
    {
        providerIdKeyString = muNew.ProviderUserKey.ToString();
    }
    <span class="kwrd">else</span>
    {
        providerIdKeyString = <span class="kwrd">string</span>.Empty;  <span class="rem">// failed</span>
    }
    <span class="kwrd">return</span>;
}</pre>
<p></p>
<p class="style4">Figure 1 &#8211; The New Insert Method to be added to MembershipUserODS.cs</p>
<p>If you want to turn the Guid passed back into a native Guid type do the following. (this could be useful if you want to retrieve the current username as shown below.</p>
<p></p>
<pre class="csharpcode">
Guid myNewGuild = <span class="kwrd">new</span> Guid(providerIdKeyString);
MembershipUser myCurrentMembershipUser = Membership.GetUser(myNewGuild);
<span class="kwrd">string</span> memberName = myCurrentMembershipUser.UserName;</pre>
<p></p>
<p class="style4">Figure 2 &#8211; Example of converting created ProviderUseKey to Guid and retreiving username</p>
<p>Now that we have the new Insert Method defined the easiest thing to do is use it directly. Below is a complete aspx page that references the new method as well as a screen shot of what it looks like to add a new member. Notice that the status label is returning the providerUserKey.</p>
<p><img src="http://peterkellner.net/images/MSDN_Membership/returnkey1.jpg" /></p>
<p><img src="http://peterkellner.net/images/MSDN_Membership/returnkey2.jpg" /></p>
<p class="style4">Figure 3 &#8211; Examples of adding a new user with a valid password, and one without a valid password</p>
<p></p>
<pre class="csharpcode">
<span class="kwrd">&lt;</span> %@ Page Language="C#" <span class="asp">%&gt;</span>
<span class="kwrd">&lt;</span> !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>

    <span class="kwrd">protected</span> <span class="kwrd">void</span> ButtonNewUser_Click(<span class="kwrd">object</span> sender, EventArgs e)
    {
        MembershipCreateStatus membershipCreateStatus;
        <span class="kwrd">string</span> providerIdKeyString = <span class="kwrd">string</span>.Empty;
        MembershipUtilities.MembershipUserODS.Insert(TextBoxUserName.Text,
            CheckboxApproval.Checked,
            TextBoxEmail.Text,
            TextBoxPasswordQuestion.Text,
            TextBoxPassword.Text,
            TextBoxPasswordAnswer.Text,
            <span class="kwrd">out</span> membershipCreateStatus,
            <span class="kwrd">out</span> providerIdKeyString
        );
        <span class="kwrd">if</span> (membershipCreateStatus == MembershipCreateStatus.Success)
        {
            LabelInsertMessage.Text = <span class="str">"New User Create Successfully.  Key: "</span> + providerIdKeyString;
        }
        <span class="kwrd">else</span>
        {
            LabelInsertMessage.Text = membershipCreateStatus.ToString();
        }

        <span class="kwrd">return</span>;
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>Untitled Page<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr"> <img src='http://PetersBlogCDN.s3.amazonaws.com/wp/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </span> <span class="attr">anel</span> <span class="attr">ID</span><span class="kwrd">="PanelCreateUser"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">BorderColor</span><span class="kwrd">="Black"</span> <span class="attr">BorderWidth</span><span class="kwrd">="1px"</span>
                <span class="attr">Height</span><span class="kwrd">="50px"</span> <span class="attr">Width</span><span class="kwrd">="125px"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">cellpadding</span><span class="kwrd">="3"</span> <span class="attr">cellspacing</span><span class="kwrd">="3"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label3"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="UserName"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxUserName"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label4"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Password"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span> <span class="attr">style</span><span class="kwrd">="height: 32px"</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxPassword"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label5"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="PasswordQuestion"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxPasswordQuestion"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label6"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="PasswordAnswer"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxPasswordAnswer"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label2"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Email"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:TextBox</span> <span class="attr">ID</span><span class="kwrd">="TextBoxEmail"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="Label9"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span><span class="kwrd">="Approved"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:CheckBox</span> <span class="attr">ID</span><span class="kwrd">="CheckboxApproval"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                        <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                            <span class="kwrd">&lt;</span><span class="html">asp</span> <span class="attr">:Button</span> <span class="attr">ID</span><span class="kwrd">="ButtonNewUser"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">OnClick</span><span class="kwrd">="ButtonNewUser_Click"</span> <span class="attr">Text</span><span class="kwrd">="Create New User"</span> <span class="kwrd">/&gt;</span>
                        <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;&lt;</span><span class="html">asp</span> <span class="attr">:Label</span> <span class="attr">ID</span><span class="kwrd">="LabelInsertMessage"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<p></p>
<p class="style4">Figure 4 &#8211; complete aspx page excercising new insert method</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2006/01/10/using-membeship-objectdatasource-for-returning-provideruserkey/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 33/38 queries in 0.011 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-22 10:39:04 -->
