<?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; GridView</title>
	<atom:link href="http://peterkellner.net/category/gridview/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>Using ASP.NET Web Forms, Passing Primary Key to RowCommand Event</title>
		<link>http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-asp-net-web-forms-passing-primary-key-to-rowcommand-event</link>
		<comments>http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 15:01:54 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[WebForms]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/</guid>
		<description><![CDATA[&#160;
I know this is old hat, but after recently having a conversation with one of the ASP.NET Team guys about how easy Web Forms is to use, I thought I’d just post a simple example of that.&#160; Here is the scenario.&#160; You have a simple GridView with just three columns (Select,Id,TagName).&#160; You want to be [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>I know this is old hat, but after recently having a conversation with one of the <a href="http://www.asp.net/">ASP.NET</a> Team guys about how easy <a href="http://www.asp.net/web-forms">Web Forms</a> is to use, I thought I’d just post a simple example of that.&#160; Here is the scenario.&#160; You have a simple <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx">GridView</a> with just three columns (Select,Id,TagName).&#160; You want to be able to capture what happens when the user pressed the Select command and capture the Id.&#160; It looks like this:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb.png" width="196" height="244" /></a></p>
<p>&#160;</p>
<p>And has an aspx page like this:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;GridViewNotSelected&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">AllowSorting</span><span style="color: #0000ff">=&quot;True&quot;</span>         <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">=&quot;False&quot;</span>         <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">=&quot;SqlDataSourceTagsNotSelected&quot;</span>         <span style="color: #ff0000">onrowcommand</span><span style="color: #0000ff">=&quot;GridViewNotSelected_RowCommand&quot;</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">Columns</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</span> <span style="color: #ff0000">ShowHeader</span><span style="color: #0000ff">=&quot;False&quot;</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:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;LinkButton1&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span>                     <span style="color: #ff0000">CausesValidation</span><span style="color: #0000ff">=&quot;False&quot;</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='&lt;%# Eval(&quot;Id&quot;) %&gt;'</span>                    <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">=&quot;Select&quot;</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">=&quot;Select&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:LinkButton</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:TemplateField</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</span>             <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">=&quot;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&quot;</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">&gt;</span>        <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:TemplateField</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:Label</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;Label1&quot;</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">='&lt;%# Eval(&quot;TagName&quot;) %&gt;'</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:Label</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:TemplateField</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">Columns</span><span style="color: #0000ff">&gt;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p></div>
<p>Notice that in the <a href="http://weblogs.asp.net/scottgu/archive/2006/06/04/Supporting-Templates-with-ASP.NET-User-Controls.aspx">TemplateField</a> there is LinkButton with a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandargument.aspx">CommandArgument</a> that simply extracts the TagName with the current Id of the <a href="http://msdn.microsoft.com/en-us/library/dz12d98w.aspx">SqlDataSource</a>.&#160; Now, all you need is the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx">RowCommand</a> event and you are done.&#160; Here it is in <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336706">C#.</a></p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> GridViewNotSelected_RowCommand(<span style="color: #0000ff">object</span> sender, GridViewCommandEventArgs e){    <span style="color: #0000ff">int</span> tagsId = Convert.ToInt32(e.CommandArgument);}</pre>
<p></div>
<p>And finally, the proof!</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb1.png" width="627" height="118" /></a></p>
<p>&#160;</p>
<p>Very very simple.&#160; HTH’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/05/using-asp-net-web-forms-passing-primary-key-to-rowcommand-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Disable Edit/Insert/New Buttons in DetailsView or GridView (ASP.NET 2.0+)</title>
		<link>http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=detailsview-gridview-aspnet-disable-new-edit-delete-buttons</link>
		<comments>http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 00:27:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[DetailsView]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/</guid>
		<description><![CDATA[So, this is kind of embarrassing, that it took me a while to figure this out.&#160; I have not been doing pure asp.net server control programming for a while, but I figure since it took me a while, maybe there is someone else in the same boat.
So, you have a GridView or DetailsView that has [...]]]></description>
			<content:encoded><![CDATA[<p>So, this is kind of embarrassing, that it took me a while to figure this out.&#160; I have not been doing pure asp.net server control programming for a while, but I figure since it took me a while, maybe there is someone else in the same boat.</p>
<p>So, you have a GridView or <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview(VS.80).aspx">DetailsView</a> that has standard “Edit” “Update” “New” type command buttons on them.&#160; The way they get there is by having the declaration something like this:</p>
<p> <span id="more-352"></span>
<pre class="csharpcode"> &lt;asp:DetailsView ID=<span class="str">&quot;DetailsView1&quot;</span> runat=<span class="str">&quot;server&quot;</span> Height=<span class="str">&quot;50px&quot;</span> Width=<span class="str">&quot;125px&quot;</span>
            AllowPaging=<span class="str">&quot;True&quot;</span> AutoGenerateRows=<span class="str">&quot;False&quot;</span> DataKeyNames=<span class="str">&quot;Id&quot;</span>
            DataSourceID=<span class="str">&quot;SqlDataSource1&quot;</span>&gt;
            &lt;Fields&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;Id&quot;</span> HeaderText=<span class="str">&quot;Id&quot;</span> ReadOnly=<span class="str">&quot;True&quot;</span>
                    SortExpression=<span class="str">&quot;Id&quot;</span> /&gt;
                &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;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampStartDate&quot;</span> HeaderText=<span class="str">&quot;CampStartDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampStartDate&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampEndDate&quot;</span> HeaderText=<span class="str">&quot;CampEndDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampEndDate&quot;</span> /&gt;
                &lt;asp:CommandField ShowEditButton=<span class="str">&quot;True&quot;</span> ShowInsertButton=<span class="str">&quot;True&quot;</span> /&gt;
            &lt;/Fields&gt;
&lt;/asp:DetailsView&gt;</pre>
<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>What you want is to say something like:</p>
<p>“I only want admin’s to be able to add new rows so&#160; want to hide the “new” button based on that”</p>
<p>So, first thing is to convert the field to a template from the following menu.&#160; You do this by using the little helper in the upper right hand corner of the detailsview (in design mode), chose Edit Fields, CommandField, then convert to template (as in the picture below).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/HowtoDisableEditInsertNewButtonsinDeta.0_F26A/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/HowtoDisableEditInsertNewButtonsinDeta.0_F26A/image_thumb.png" width="521" height="299" /></a></p>
<p>Then, you will have something like this:</p>
<pre class="csharpcode"> &lt;asp:DetailsView ID=<span class="str">&quot;DetailsView1&quot;</span> runat=<span class="str">&quot;server&quot;</span> Height=<span class="str">&quot;50px&quot;</span> Width=<span class="str">&quot;125px&quot;</span>
            AllowPaging=<span class="str">&quot;True&quot;</span> AutoGenerateRows=<span class="str">&quot;False&quot;</span> DataKeyNames=<span class="str">&quot;Id&quot;</span>
            DataSourceID=<span class="str">&quot;SqlDataSource1&quot;</span>&gt;
            &lt;Fields&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;Id&quot;</span> HeaderText=<span class="str">&quot;Id&quot;</span> ReadOnly=<span class="str">&quot;True&quot;</span>
                    SortExpression=<span class="str">&quot;Id&quot;</span> /&gt;
                &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;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampStartDate&quot;</span> HeaderText=<span class="str">&quot;CampStartDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampStartDate&quot;</span> /&gt;
                &lt;asp:BoundField DataField=<span class="str">&quot;CampEndDate&quot;</span> HeaderText=<span class="str">&quot;CampEndDate&quot;</span>
                    SortExpression=<span class="str">&quot;CampEndDate&quot;</span> /&gt;
                &lt;asp:TemplateField ShowHeader=<span class="str">&quot;False&quot;</span>&gt;
                    &lt;ItemTemplate&gt;
                        &lt;asp:LinkButton ID=<span class="str">&quot;LinkButton1&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;Edit&quot;</span> Text=<span class="str">&quot;Edit&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                        &amp;nbsp;&lt;asp:LinkButton ID=<span class="str">&quot;LinkButton2&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;New&quot;</span> Text=<span class="str">&quot;New&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                    &lt;/ItemTemplate&gt;
                    &lt;EditItemTemplate&gt;
                        &lt;asp:LinkButton ID=<span class="str">&quot;LinkButton1&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;True&quot;</span>
                            CommandName=<span class="str">&quot;Update&quot;</span> Text=<span class="str">&quot;Update&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                        &amp;nbsp;&lt;asp:LinkButton ID=<span class="str">&quot;LinkButton2&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;Cancel&quot;</span> Text=<span class="str">&quot;Cancel&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                    &lt;/EditItemTemplate&gt;
                    &lt;InsertItemTemplate&gt;
                        &lt;asp:LinkButton ID=<span class="str">&quot;LinkButton1&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;True&quot;</span>
                            CommandName=<span class="str">&quot;Insert&quot;</span> Text=<span class="str">&quot;Insert&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                        &amp;nbsp;&lt;asp:LinkButton ID=<span class="str">&quot;LinkButton2&quot;</span> runat=<span class="str">&quot;server&quot;</span> CausesValidation=<span class="str">&quot;False&quot;</span>
                            CommandName=<span class="str">&quot;Cancel&quot;</span> Text=<span class="str">&quot;Cancel&quot;</span>&gt;&lt;/asp:LinkButton&gt;
                    &lt;/InsertItemTemplate&gt;
                &lt;/asp:TemplateField&gt;
            &lt;/Fields&gt;
&lt;/asp:DetailsView&gt;</pre>
<p>
  </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;*/
}
.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, you have standard &lt;asp:LinkButton&gt; so you can call the visible property from your codebehind like this:</p>
<pre class="csharpcode"> <span class="kwrd">&lt;</span><span class="html">asp:TemplateField</span> <span class="attr">ShowHeader</span><span class="kwrd">=&quot;False&quot;</span><span class="kwrd">&gt;</span>
                     <span class="kwrd">&lt;</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span>
                         <span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;LinkButton1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span> <span class="attr">Visible</span><span class="kwrd">='&lt;%# GetShowEditButton() %&gt;'</span>
                             <span class="attr">CommandName</span><span class="kwrd">=&quot;Edit&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Edit&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span>
                         <span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;LinkButton2&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span> <span class="attr">Visible</span><span class="kwrd">='&lt;%# GetShowInsertButton() %&gt;'</span>
                             <span class="attr">CommandName</span><span class="kwrd">=&quot;New&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;New&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span>
                         <span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:LinkButton</span> <span class="attr">ID</span><span class="kwrd">=&quot;LinkButton3&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">CausesValidation</span><span class="kwrd">=&quot;False&quot;</span>
                             <span class="attr">CommandName</span><span class="kwrd">=&quot;Delete&quot;</span> <span class="attr">Text</span><span class="kwrd">=&quot;Delete&quot;</span> <span class="attr">Visible</span><span class="kwrd">='&lt;%# GetShowDeleteButton() %&gt;'</span>     <span class="kwrd">&gt;&lt;/</span><span class="html">asp:LinkButton</span><span class="kwrd">&gt;</span>
                     <span class="kwrd">&lt;/</span><span class="html">ItemTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">asp:TemplateField</span><span class="kwrd">&gt;</span></pre>
<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>Then, in your codebehind, you have the following:</p>
<pre class="csharpcode"> <span class="kwrd">protected</span> <span class="kwrd">bool</span> GetShowEditButton()
    {
        <span class="kwrd">return</span> Roles.IsUserInRole(<span class="str">&quot;Admin&quot;</span>);
    }

    <span class="kwrd">protected</span> <span class="kwrd">bool</span> GetShowInsertButton()
    {
        <span class="kwrd">return</span> Roles.IsUserInRole(<span class="str">&quot;Admin&quot;</span>);
    }
    <span class="kwrd">protected</span> <span class="kwrd">bool</span> GetShowDeleteButton()
    {
        <span class="kwrd">return</span> Roles.IsUserInRole(<span class="str">&quot;Admin&quot;</span>);
    }
}</pre>
<p>Hope you find this before spending a bunch of time reading about more complicated solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>How To Access Content From MasterPage in ASP.NET</title>
		<link>http://peterkellner.net/2009/03/20/aspnet-masterpage-content-search-findcontrol/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=aspnet-masterpage-content-search-findcontrol</link>
		<comments>http://peterkellner.net/2009/03/20/aspnet-masterpage-content-search-findcontrol/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 16:41:28 +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[MasterPages]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=272</guid>
		<description><![CDATA[So, you want to access some content from inside a page that you created from an existing master page?&#160; The most clean way to do this is to create a public property in your master page, then access that.&#160; In my case, I have a search button on a master page that I want to [...]]]></description>
			<content:encoded><![CDATA[<p>So, you want to access some content from inside a page that you created from an existing <a href="http://msdn.microsoft.com/en-us/library/4xh7yfby(VS.80).aspx">master page</a>?&#160; The most clean way to do this is to create a public property in your master page, then access that.&#160; In my case, I have a search button on a master page that I want to use from inside to pages that derive from that page.&#160; So, Here is how I declare my master page:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> &lt;%@ Master Language=<span style="color: #006080">&quot;C#&quot;</span> MasterPageFile=<span style="color: #006080">&quot;~/MasterPages/MasterPage.Master&quot;</span> AutoEventWireup=<span style="color: #006080">&quot;true&quot;</span></pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span>     CodeBehind=<span style="color: #006080">&quot;ContactMasterPage.master.cs&quot;</span> Inherits=<span style="color: #006080">&quot;ThreePLogic.Web.ASPWeb.ContactPages.ContactMasterPage&quot;</span> %&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span>&#160; </pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> &lt;asp:Content ID=<span style="color: #006080">&quot;Content5&quot;</span> ContentPlaceHolderID=<span style="color: #006080">&quot;ContentCenter&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span>&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span>         &lt;asp:TextBox ID=<span style="color: #006080">&quot;TextBoxSearchName&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span> Width=<span style="color: #006080">&quot;200px&quot;</span> CssClass=<span style="color: #006080">&quot;InputText&quot;</span>&gt;&lt;/asp:TextBox&gt;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span>         &lt;asp:Button ID=<span style="color: #006080">&quot;ButtonSearchName&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span> CssClass=<span style="color: #006080">&quot;SearchBtn&quot;</span> /&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span>         &lt;/div&gt;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span> &lt;/div&gt;</pre>
</p></div>
</div>
<p><span id="more-272"></span></p>
<p>In my codebind for my masterpage, I have the following:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> <span style="color: #0000ff">using</span> System;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> <span style="color: #0000ff">using</span> System.Web.UI;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span> <span style="color: #0000ff">using</span> System.Web.UI.WebControls;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> <span style="color: #0000ff">using</span> ThreePLogic.Data.ThreePLogicAccess;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span>&#160; </pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> <span style="color: #0000ff">namespace</span> ThreePLogic.Web.ASPWeb.ContactPages</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span> {</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> ContactMasterPage : MasterPage</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span>     {</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> SearchText</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span>         {</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span>             get</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span>             {</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span>                 TextBox textBoxSearch = Master.FindControl(<span style="color: #006080">&quot;ContentCenter&quot;</span>).FindControl(<span style="color: #006080">&quot;TextBoxSearchName&quot;</span>) <span style="color: #0000ff">as</span> TextBox;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span>                 <span style="color: #0000ff">if</span> (textBoxSearch != <span style="color: #0000ff">null</span>)</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span>                 {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span>                     <span style="color: #0000ff">return</span> textBoxSearch.Text;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  18:</span>                 }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  19:</span>                 <span style="color: #0000ff">else</span></pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  20:</span>                 {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  21:</span>                     <span style="color: #0000ff">return</span> String.Empty;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  22:</span>                 }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  23:</span>                 </pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  24:</span>             }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  25:</span>         }</pre>
</p></div>
</div>
<p>&#160;</p>
<p>Then, in my page I derive from the masterpage I have the following.&#160; Notice that I include the masterpage type so I can have type safe access to the public property.</p>
<p>&#160;</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> &lt;%@ Master Language=<span style="color: #006080">&quot;C#&quot;</span> MasterPageFile=<span style="color: #006080">&quot;~/ContactPages/ContactMasterPage.Master&quot;</span></pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span>     AutoEventWireup=<span style="color: #006080">&quot;true&quot;</span> CodeBehind=<span style="color: #006080">&quot;ContactCompanyMasterPage.master.cs&quot;</span> Inherits=<span style="color: #006080">&quot;ThreePLogic.Web.ASPWeb.ContactPages.ContactCompany.ContactCompanyMasterPage&quot;</span> %&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span>&#160; </pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> &lt;%@ MasterType TypeName=<span style="color: #006080">&quot;ThreePLogic.Web.ASPWeb.ContactPages.ContactMasterPage&quot;</span> %&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span>&#160; </pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> &lt;asp:Content ID=<span style="color: #006080">&quot;Content1&quot;</span> ContentPlaceHolderID=<span style="color: #006080">&quot;GridContent&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span>&gt;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span>&#160; </pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span>     &lt;asp:Label ID=<span style="color: #006080">&quot;LabelSearchMirror&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span> Text=<span style="color: #006080">&quot;&quot;</span>   Visible=<span style="color: #006080">&quot;false&quot;</span> &gt;&lt;/asp:Label&gt;</pre>
</p></div>
</div>
<p>&#160;</p>
<p>Then, finally, in the codebehind, this is how I access my search box.&#160; In my case, I assign it to an invisible label, then I can have server side presentation controls, like <a href="http://www.aspnet101.com/aspnet101/tutorials.aspx?id=51">GridView</a>, access it as a select parameter.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> <span style="color: #0000ff">using</span> System;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> <span style="color: #0000ff">using</span> System.Web.UI;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span> <span style="color: #0000ff">using</span> System.Web.UI.WebControls;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> <span style="color: #0000ff">using</span> ThreePLogic.Common.Enums;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span> <span style="color: #0000ff">using</span> ThreePLogic.Web.ASPWeb.Code;</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span>&#160; </pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span> <span style="color: #0000ff">namespace</span> ThreePLogic.Web.ASPWeb.ContactPages.ContactCompany</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span> {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> ContactCompanyMasterPage : MasterPage</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span>     {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span>         <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_PreRender(<span style="color: #0000ff">object</span> sender, EventArgs e)</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span>         {</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span>             GridViewCompany.PageIndex = UserService.I.GetCookieSelectedId(CookieIdType.CompanyCurrentPage);</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span>             <span style="color: #0000ff">if</span> (!String.IsNullOrEmpty(Master.SearchText))</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span>             {</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span>                 LabelSearchMirror.Text = Master.SearchText;</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span>                 GridViewCompany.DataBind();</pre>
<pre style="border-bottom-style: none; 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: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  18:</span>             }</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  19:</span>         }</pre>
</p></div>
</div>
<p>Good luck, and hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/03/20/aspnet-masterpage-content-search-findcontrol/feed/</wfw:commentRss>
		<slash:comments>2</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>
	</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 10/38 queries in 0.009 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-22 10:15:30 -->
