<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How to Set the Default Value of a DropDownList in an ASP.NET Page</title>
	<atom:link href="http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dropdownlistdefaultsetting</link>
	<description>Microsoft Focused, JavaScript,HTML5 (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Tue, 15 May 2012 21:53:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: ANITA</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-35077</link>
		<dc:creator>ANITA</dc:creator>
		<pubDate>Fri, 10 Feb 2012 07:14:21 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-35077</guid>
		<description>peter’s solution is working properly.
it&#039;s working</description>
		<content:encoded><![CDATA[<p>peter’s solution is working properly.<br />
it&#8217;s working</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Proby</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-32806</link>
		<dc:creator>Proby</dc:creator>
		<pubDate>Wed, 07 Dec 2011 14:41:50 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-32806</guid>
		<description>Hi,

I&#039;ve got a similar problem. I contruct this list :

data = TechnicienMgr.GetTechsOfGroupe(idGroupe);

lstTechniciens.DataSource = data;
lstTechniciens.DataValueField = &quot;UTCLEUNIK&quot;;
lstTechniciens.DataTextField = &quot;NOM_PRENOM&quot;;
lstTechniciens.DataBind();

and i want to select by default the item where &quot;UTCLEUNIK&quot; = &quot;6545&quot;

Can you help me ?</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;ve got a similar problem. I contruct this list :</p>
<p>data = TechnicienMgr.GetTechsOfGroupe(idGroupe);</p>
<p>lstTechniciens.DataSource = data;<br />
lstTechniciens.DataValueField = &#8220;UTCLEUNIK&#8221;;<br />
lstTechniciens.DataTextField = &#8220;NOM_PRENOM&#8221;;<br />
lstTechniciens.DataBind();</p>
<p>and i want to select by default the item where &#8220;UTCLEUNIK&#8221; = &#8220;6545&#8243;</p>
<p>Can you help me ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricardo</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-32291</link>
		<dc:creator>Ricardo</dc:creator>
		<pubDate>Mon, 28 Nov 2011 20:17:13 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-32291</guid>
		<description>Just found this approach, it works great for me:

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf( DropDownList1.Items.FindByText( defaultText)); 

Vía http://techbrij.com/627/select-item-aspdotnet-dropdownlist-programmatically</description>
		<content:encoded><![CDATA[<p>Just found this approach, it works great for me:</p>
<p>DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf( DropDownList1.Items.FindByText( defaultText)); </p>
<p>Vía <a href="http://techbrij.com/627/select-item-aspdotnet-dropdownlist-programmatically">http://techbrij.com/627/select-item-aspdotnet-dropdownlist-programmatically</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gerd symptoms</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-30544</link>
		<dc:creator>gerd symptoms</dc:creator>
		<pubDate>Sat, 03 Sep 2011 12:58:33 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-30544</guid>
		<description>I found your blog via google and am so glad I did! I’m doing exactly the same thing you are but for myself, not for a book … so you can bet I’ll be returning often!</description>
		<content:encoded><![CDATA[<p>I found your blog via google and am so glad I did! I’m doing exactly the same thing you are but for myself, not for a book … so you can bet I’ll be returning often!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kiruthika</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-30338</link>
		<dc:creator>kiruthika</dc:creator>
		<pubDate>Mon, 08 Aug 2011 10:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-30338</guid>
		<description>yes.. peter&#039;s solution is working properly.</description>
		<content:encoded><![CDATA[<p>yes.. peter&#8217;s solution is working properly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uiouio</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29703</link>
		<dc:creator>uiouio</dc:creator>
		<pubDate>Thu, 31 Mar 2011 22:22:09 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29703</guid>
		<description>gand tari mani</description>
		<content:encoded><![CDATA[<p>gand tari mani</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uiouio</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29702</link>
		<dc:creator>uiouio</dc:creator>
		<pubDate>Thu, 31 Mar 2011 22:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29702</guid>
		<description>uiiiiiiiiiiiiiiiii</description>
		<content:encoded><![CDATA[<p>uiiiiiiiiiiiiiiiii</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leonard</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29640</link>
		<dc:creator>Leonard</dc:creator>
		<pubDate>Wed, 16 Mar 2011 11:37:25 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29640</guid>
		<description>Thank you. it is working properly.</description>
		<content:encoded><![CDATA[<p>Thank you. it is working properly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shah</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29612</link>
		<dc:creator>Shah</dc:creator>
		<pubDate>Fri, 11 Mar 2011 07:16:35 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-29612</guid>
		<description>Peter&#039;s solution is perfect as compare to other solutions because the only solution works for me is his solution when i used it with sharepoint web parts or other update panel cotainers.</description>
		<content:encoded><![CDATA[<p>Peter&#8217;s solution is perfect as compare to other solutions because the only solution works for me is his solution when i used it with sharepoint web parts or other update panel cotainers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Kellner</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-28053</link>
		<dc:creator>Peter Kellner</dc:creator>
		<pubDate>Fri, 10 Sep 2010 05:01:07 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-28053</guid>
		<description>I like almost everyones solutions better than mine. I just had to do this again in codecamp project for speakers picking shirt sizes and this is what I ended up with.  Very similar to others:

ListItem listItem = DropDownListSpeakerShirtSize.Items.FindByValue(Attendee.ShirtSize);
if (listItem != null)
{
    DropDownListSpeakerShirtSize.SelectedValue = listItem.Value;
}</description>
		<content:encoded><![CDATA[<p>I like almost everyones solutions better than mine. I just had to do this again in codecamp project for speakers picking shirt sizes and this is what I ended up with.  Very similar to others:</p>
<p>ListItem listItem = DropDownListSpeakerShirtSize.Items.FindByValue(Attendee.ShirtSize);<br />
if (listItem != null)<br />
{<br />
    DropDownListSpeakerShirtSize.SelectedValue = listItem.Value;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trev</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-27708</link>
		<dc:creator>Trev</dc:creator>
		<pubDate>Wed, 09 Jun 2010 22:28:28 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-27708</guid>
		<description>Hi, although its a bit old now thanks for the above discussion as it lead me towards my solution. The problem is I wanted a dropdownlist to default to a specific value not the first in the list (from my database) and using:-

protected void Page_Load(object sender, EventArgs e)
{
    maxCostDDList.SelectedValue = &quot;1500&quot;;
}

just set the dropdown list to 1500 every time the page was submitted, not good. But thanks to suggestions on here this worked for me:-

protected void maxCostDDList_DataBound(object sender, EventArgs e)
{
if (maxCostDDList.Items.FindByValue(&quot;1500&quot;) != null)
    {
       maxCostDDList.SelectedValue = &quot;1500&quot;;
    }
}

did try &quot;-1&quot; but that didn&#039;t work for me.

Cheers to all.</description>
		<content:encoded><![CDATA[<p>Hi, although its a bit old now thanks for the above discussion as it lead me towards my solution. The problem is I wanted a dropdownlist to default to a specific value not the first in the list (from my database) and using:-</p>
<p>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
    maxCostDDList.SelectedValue = &#8220;1500&#8243;;<br />
}</p>
<p>just set the dropdown list to 1500 every time the page was submitted, not good. But thanks to suggestions on here this worked for me:-</p>
<p>protected void maxCostDDList_DataBound(object sender, EventArgs e)<br />
{<br />
if (maxCostDDList.Items.FindByValue(&#8220;1500&#8243;) != null)<br />
    {<br />
       maxCostDDList.SelectedValue = &#8220;1500&#8243;;<br />
    }<br />
}</p>
<p>did try &#8220;-1&#8243; but that didn&#8217;t work for me.</p>
<p>Cheers to all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakthi</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25434</link>
		<dc:creator>sakthi</dc:creator>
		<pubDate>Thu, 01 Oct 2009 09:13:57 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25434</guid>
		<description>How can assign a item to dropdownlist in runtime..

that dropdownlist already loaded with somevalue like jan,feb,mar,apr

i want to assgin a value feb at runtime...

how can i assogn it...</description>
		<content:encoded><![CDATA[<p>How can assign a item to dropdownlist in runtime..</p>
<p>that dropdownlist already loaded with somevalue like jan,feb,mar,apr</p>
<p>i want to assgin a value feb at runtime&#8230;</p>
<p>how can i assogn it&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Murugan Andezuthu Dharmaratnam</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25283</link>
		<dc:creator>Murugan Andezuthu Dharmaratnam</dc:creator>
		<pubDate>Sun, 30 Aug 2009 14:05:11 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25283</guid>
		<description>You could easily set the value of the drop down list . Either using code or 
directly in the aspx file. 






&lt;/

Read More
&lt;a href=&quot;http://muruganad.com/ASP.NET/ASP_.NET_Drop_Down_List_Default_Value.html&quot; rel=&quot;nofollow&quot;&gt;http://muruganad.com/ASP.NET/ASP_.NET_Drop_Down_List_Default_Value.html&lt;/a&gt;

Thanks!
  &lt;a href=&quot;http://muruganad.com&quot; rel=&quot;nofollow&quot;&gt;Murugan Andezuthu Dharmaratnam&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>You could easily set the value of the drop down list . Either using code or<br />
directly in the aspx file. </p>
<p>&lt;/</p>
<p>Read More<br />
<a href="http://muruganad.com/ASP.NET/ASP_.NET_Drop_Down_List_Default_Value.html">http://muruganad.com/ASP.NET/ASP_.NET_Drop_Down_List_Default_Value.html</a></p>
<p>Thanks!<br />
  <a href="http://muruganad.com">Murugan Andezuthu Dharmaratnam</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25029</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Thu, 25 Jun 2009 11:01:28 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25029</guid>
		<description>Correction - The above worked for FF but not for IE (I&#039;ve no idea why since its server side code) Anyway the below worked for both

protected void DropDownListOrg_DataBound(object sender, EventArgs e)
{
if (DropDownListOrg.Items.FindByValue(&quot;-1&quot;) != null)
DropDownListOrg.SelectedValue = &quot;-1&quot;;
}</description>
		<content:encoded><![CDATA[<p>Correction &#8211; The above worked for FF but not for IE (I&#8217;ve no idea why since its server side code) Anyway the below worked for both</p>
<p>protected void DropDownListOrg_DataBound(object sender, EventArgs e)<br />
{<br />
if (DropDownListOrg.Items.FindByValue(&#8220;-1&#8243;) != null)<br />
DropDownListOrg.SelectedValue = &#8220;-1&#8243;;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25028</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Thu, 25 Jun 2009 10:07:03 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-25028</guid>
		<description>I recommend a mixture of the abpve methods. This way you get the default value and protect against exceptions

protected void Page_Load(object sender, EventArgs e)
{
if (DropDownListOrg.Items.FindByValue(&quot;-1&quot;) != null)
DropDownListOrg.SelectedValue = &quot;-1&quot;;
}</description>
		<content:encoded><![CDATA[<p>I recommend a mixture of the abpve methods. This way you get the default value and protect against exceptions</p>
<p>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (DropDownListOrg.Items.FindByValue(&#8220;-1&#8243;) != null)<br />
DropDownListOrg.SelectedValue = &#8220;-1&#8243;;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Footer</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-24854</link>
		<dc:creator>Frank Footer</dc:creator>
		<pubDate>Wed, 03 Jun 2009 00:03:44 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-24854</guid>
		<description>in the Page_Load method in the code behind for my apsx page I added this to set the initial value of a drop down list:

      protected void Page_Load(object sender, EventArgs e)
        {
            v_state.SelectedValue = &quot;AK&quot;;
        }</description>
		<content:encoded><![CDATA[<p>in the Page_Load method in the code behind for my apsx page I added this to set the initial value of a drop down list:</p>
<p>      protected void Page_Load(object sender, EventArgs e)<br />
        {<br />
            v_state.SelectedValue = &#8220;AK&#8221;;<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-24811</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Wed, 20 May 2009 11:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-24811</guid>
		<description>I&#039;m not sure how, but I&#039;m sure you could do it client side. -Peter</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure how, but I&#8217;m sure you could do it client side. -Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jjsoriano</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-24810</link>
		<dc:creator>jjsoriano</dc:creator>
		<pubDate>Wed, 20 May 2009 08:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-24810</guid>
		<description>I see no reason why you need to do it in server side. is there anyway to do it in the client side?</description>
		<content:encoded><![CDATA[<p>I see no reason why you need to do it in server side. is there anyway to do it in the client side?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neo</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-11959</link>
		<dc:creator>Neo</dc:creator>
		<pubDate>Wed, 03 Dec 2008 18:29:51 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-11959</guid>
		<description>Be careful.
DropDownListUser.Items.FindByValue(Context.User.Identity.Name) may return null. When it does, you may get &quot;object is not an instance&quot; exception.</description>
		<content:encoded><![CDATA[<p>Be careful.<br />
DropDownListUser.Items.FindByValue(Context.User.Identity.Name) may return null. When it does, you may get &#8220;object is not an instance&#8221; exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbfurlong</title>
		<link>http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-666</link>
		<dc:creator>jbfurlong</dc:creator>
		<pubDate>Wed, 02 Jul 2008 15:23:54 +0000</pubDate>
		<guid isPermaLink="false">http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/#comment-666</guid>
		<description>I use Naveen&#039;s approach too but at run time when databind occurs, if the SelectedIndex is not cleared to -1 first then you can get an http error that you cannot have more than one item selected. It goes something like
DropDownList.SelectIndex = -1;
DropDownListUser.Items.FindByValue(Context.User.Identity.Name).Selected = true;</description>
		<content:encoded><![CDATA[<p>I use Naveen&#8217;s approach too but at run time when databind occurs, if the SelectedIndex is not cleared to -1 first then you can get an http error that you cannot have more than one item selected. It goes something like<br />
DropDownList.SelectIndex = -1;<br />
DropDownListUser.Items.FindByValue(Context.User.Identity.Name).Selected = true;</p>
]]></content:encoded>
	</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 64/67 queries in 0.008 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-17 07:08:18 -->
