<?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>Eric Fickes &#187; DataBound</title>
	<atom:link href="http://ericfickes.com/tag/databound/feed/" rel="self" type="application/rss+xml" />
	<link>http://ericfickes.com</link>
	<description>Design minded Internet Programmer</description>
	<lastBuildDate>Fri, 28 Oct 2011 04:14:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Use SQL to insert a label in front of a DataBound list</title>
		<link>http://ericfickes.com/2010/06/use-sql-to-insert-a-label-in-front-of-a-databound-list/</link>
		<comments>http://ericfickes.com/2010/06/use-sql-to-insert-a-label-in-front-of-a-databound-list/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 02:35:27 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[DataBind]]></category>
		<category><![CDATA[DataBound]]></category>
		<category><![CDATA[union]]></category>
		<category><![CDATA[viewstate]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1473</guid>
		<description><![CDATA[Here&#8217;s a clever little solution I would like to add to the book of &#8216;get it done&#8217;.  While this particular example uses ASP.NET controls, this concept really applies to any language that supports DataBinding to a control. The base concept &#8230; <a href="http://ericfickes.com/2010/06/use-sql-to-insert-a-label-in-front-of-a-databound-list/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a clever little solution I would like to add to the book of &#8216;get it done&#8217;.  While this particular example uses ASP.NET controls, this concept really applies to any language that supports DataBinding to a control.</p>
<p>The base concept is using your knowledge of SQL&#8217;s UNION operator to add a temp value to the beginning of a list of data from a sql query.  In the past I&#8217;ve done this countless times via code, and recently I didn&#8217;t have the time to do this, so I updated the query to a UNION, and I was good to go.</p>
<p>Now I&#8217;m not selling this as a &#8216;best practice&#8217;, but I do consider this one more reason why it&#8217;s good to know SQL.</p>
<p><strong>Problem</strong> : Using a SQLDataSource to populate a DropDown component, how do you inject a spacer value in position 0?  EX : &#8220;- select value -&#8221;</p>
<p><strong>Solution</strong> : Inject your spacer value in your SelectCommand via sql&#8217;s UNION operator</p>
<h3>ComboBox</h3>
<pre class="brush: csharp; title: ; notranslate">
&lt;asp:DropDownList runat=&quot;server&quot; ID=&quot;meter_manufacturer_dd&quot; DataSourceID=&quot;sql_meterManufacturer&quot; DataTextField=&quot;Manufacturer&quot; /&gt;
</pre>
<h2>DataSource</h2>
<pre class="brush: sql; title: ; notranslate">
&lt;asp:SqlDataSource runat=&quot;server&quot; ID=&quot;sql_meterManufacturer&quot;
    SelectCommand=&quot;
    SELECT '- Choose Manufacturer -' as Manufacturer
    UNION
    SELECT DISTINCT Manufacturer FROM Smart_Meter_DEF&quot;
    /&gt;</pre>
<p>What this solution gets you.</p>
<p>1. Your spacer value shows up in position 0 ( because the first character is &#8211; and not alphanumeric )</p>
<p style="text-align: center;"><a href="http://ericfickes.com/wp-content/uploads/2010/06/dropdown1.png" rel="lightbox[1473]"><img class="size-full wp-image-1474 aligncenter" title="DataBound ComboBox with spacer injected via SQL" src="http://ericfickes.com/wp-content/uploads/2010/06/dropdown1.png" alt="SQL is your friend" width="187" height="180" /></a></p>
<p style="text-align: center;">2. Auto ViewState caching ( EG : going straight .NET solution, .NET handles persisting your dropdown selection between postbacks )</p>
<p style="text-align: center;"><a href="http://ericfickes.com/wp-content/uploads/2010/06/dropdown2.png" rel="lightbox[1473]"><img class="size-full wp-image-1475 aligncenter" title="DataBound ComboBox retains selection between Postbacks" src="http://ericfickes.com/wp-content/uploads/2010/06/dropdown2.png" alt="Injecting a value via SQL eliminates need for custom ViewState handling" width="189" height="185" /></a></p>
<p>* in this sample, the connectionString for the SqlDataSource is set in code.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/06/use-sql-to-insert-a-label-in-front-of-a-databound-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieve the current row of a DataBound List Control ( .net )</title>
		<link>http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/</link>
		<comments>http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/#comments</comments>
		<pubDate>Wed, 22 Feb 2006 20:00:00 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Current Row]]></category>
		<category><![CDATA[DataBound]]></category>
		<category><![CDATA[ListControl]]></category>

		<guid isPermaLink="false">http://ericfickes.com/2006/02/22/70/</guid>
		<description><![CDATA[This has taken too long to figure out. If you want to get the current row number of an item being DataBound to a List control ( DataGrid, Repeater, etc ), use this line of code in your aspx code &#8230; <a href="http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This has taken too long to figure out.  If you want to get the current row number of an item being DataBound to a List control ( DataGrid, Repeater, etc ), use this line of code in your aspx code :</p>
<p><span style="font-family: courier new; color: #000000;"><span style="color: #990000;"><span style="font-weight: bold;">&lt;%#</span> Container.ItemIndex+1 <span style="font-weight: bold;">%&gt;</span></span></span></p>
<p>And if you want to get the number of records in your DataBound control, do this</p>
<p><span style="font-family: courier new; color: #000000;"><span style="color: #990000;"><span style="font-weight: bold;">&lt;%#</span> YourControlId.Items.Count <span style="font-weight: bold;">%&gt;</span></span></span></p>
<p><span style="font-family: courier new;">Where YourControlId is the id of your DataBound control, such as an ASP:Repeater</span></p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

