<?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>Black Ninja Software &#187; ASP.NET</title>
	<atom:link href="http://blackninjasoftware.com/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blackninjasoftware.com</link>
	<description>SharePoint and SQL Server Consulting, Business Intelligence and Reporting, ASP.NET Vancouver</description>
	<lastBuildDate>Sun, 20 Jun 2010 09:51:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to Clear and Repopulate Your ASP.NET DropDown List with jQuery</title>
		<link>http://blackninjasoftware.com/2009/06/04/how-to-clear-and-repopulate-your-aspnet-dropdown-list-with-jquery/</link>
		<comments>http://blackninjasoftware.com/2009/06/04/how-to-clear-and-repopulate-your-aspnet-dropdown-list-with-jquery/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 04:41:28 +0000</pubDate>
		<dc:creator>donabel</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://blackninjasoftware.com/?p=654</guid>
		<description><![CDATA[Yes you can call and use your ASP.NET controls from jQuery! Shereen has already posted a blog on how you can access these controls JQuery Accessing the Client Generated ID of ASP.NET Controls so feel free to check it out there first. Recently we&#8217;ve had to create a UI that has a datepicker, and the date [...]]]></description>
			<content:encoded><![CDATA[<p>Yes you can call and use your ASP.NET controls from jQuery! Shereen has already posted a blog on how you can access these controls <a title="JQuery Accessing the Client Generated ID of ASP.NET Controls" href="http://blog.qumsieh.ca/2009/03/26/jquery-accessing-the-client-generated-id-of-aspnet-controls/">JQuery Accessing the Client Generated ID of ASP.NET Controls</a> so feel free to check it out there first.</p>
<p>Recently we&#8217;ve had to create a UI that has a datepicker, and the date that a user selects should determine what values get populated in an ASP.NET dropdown.</p>
<h3>Here&#8217;s how we did it</h3>
<p>We&#8217;ve listed below the two controls we&#8217;re using in this example: a calendar control and an asp.net drop down list.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>input id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;datepicker&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text&quot;</span> <span style="color: #008000;">/&gt;</span>
<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>DropDownList ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ddlDates&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;100px&quot;</span><span style="color: #008000;">&gt;&lt;/</span>asp<span style="color: #008000;">:</span>DropDownList<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>For the date picker, we used the <a href="http://jqueryui.com/demos/datepicker/">DatePicker control from jQueryUI</a>. Their demos and documentation are a great starting point, if you have any troubles with the calendar on your site, drop us a line.</p>
<p>Next, we had to add the following references:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;http://myserver/js/jquery-1.3.2.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://myserver/js/jquery-ui-1.7.1.custom.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Then we wired it up! Good ol&#8217; jQuery!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> PopulateDropDownDates<span style="color: #009900;">&#40;</span>dateText<span style="color: #339933;">,</span> numDaysToAdd<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> selectedDate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>dateText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//clear the dropdown</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&lt;%= ddlDates.ClientID %&gt;&gt;option&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//add todays date</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&lt;%= ddlDates.ClientID %&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;option&gt;&lt;/option&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>dateText<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>dateText<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//counter</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> numDaysToAdd<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> currentDate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>selectedDate.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> selectedDate.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> selectedDate.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        currentDate <span style="color: #339933;">=</span> currentDate.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> currentDate.<span style="color: #660066;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> currentDate.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&lt;%= ddlDates.ClientID %&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;option&gt;&lt;/option&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>currentDate<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>currentDate<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#datepicker&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            onSelect<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dateText<span style="color: #339933;">,</span> inst<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                PopulateDropDownDates<span style="color: #009900;">&#40;</span>dateText<span style="color: #339933;">,</span> <span style="color: #CC0000;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Voila! That&#8217;s it. Works beautifully!</p>
]]></content:encoded>
			<wfw:commentRss>http://blackninjasoftware.com/2009/06/04/how-to-clear-and-repopulate-your-aspnet-dropdown-list-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
