<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tips &amp; Tricks</title><link>http://forums.asp.net/53.aspx</link><description>Cool code and exciting examples, provided by our members.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Selected Item in Dropdownlist in an Usercontrol</title><link>http://forums.asp.net/thread/3254587.aspx</link><pubDate>Wed, 24 Jun 2009 07:07:41 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3254587</guid><dc:creator>z0333</dc:creator><author>z0333</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3254587.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=53&amp;PostID=3254587</wfw:commentRss><description>&lt;p dir="ltr"&gt;You can add a public property to the user control that expose dropdownlist1.selecteditem.value:&lt;/p&gt;
&lt;p dir="ltr"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p dir="ltr"&gt;Public ReadOnly Property SelectedValue() As String&lt;/p&gt;
&lt;p dir="ltr"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;/p&gt;
&lt;p dir="ltr"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return dropdownlist1.selecteditem.value&lt;/p&gt;
&lt;p dir="ltr"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;/p&gt;
&lt;p dir="ltr"&gt;&amp;nbsp;End Property&lt;/p&gt;</description></item><item><title>Re: Selected Item in Dropdownlist in an Usercontrol</title><link>http://forums.asp.net/thread/3213688.aspx</link><pubDate>Fri, 05 Jun 2009 17:19:21 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3213688</guid><dc:creator>mcupryk</dc:creator><author>mcupryk</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3213688.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=53&amp;PostID=3213688</wfw:commentRss><description>&lt;p&gt;This one is not working for me.&lt;/p&gt;</description></item><item><title>Selected Item in Dropdownlist in an Usercontrol</title><link>http://forums.asp.net/thread/749214.aspx</link><pubDate>Wed, 17 Nov 2004 12:41:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:749214</guid><dc:creator>ranganh</dc:creator><author>ranganh</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/749214.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=53&amp;PostID=749214</wfw:commentRss><description>&lt;br /&gt;

&lt;br /&gt;
Hi,
&lt;br /&gt;

&lt;br /&gt;
A Common requirement we have would be to have a Dropdownlist of items which would be common across all the pages (top navigation or in the left navigation).
&lt;br /&gt;

&lt;br /&gt;
Retrieving the selected item in a dropdownlist which resides in the same page, is pretty straight forward dropdownlist1.selecteditem.value.
&lt;br /&gt;

&lt;br /&gt;
However, when it is in a usercontrol, its pretty difficult to retrieve it since you will get the &amp;quot;Object Reference not set to an instance&amp;quot; error if you try the normal method. Even if you create an instance of the usercontrol and try to access its dropdownlist, you will get the above error.
&lt;br /&gt;

&lt;br /&gt;
The following code demonstrates how to overcome this problem.
&lt;br /&gt;

&lt;br /&gt;
UserControl objCtrl = ((UserControl)(FindControl(&amp;quot;Id of the Usercontrol as declared in the container page&amp;quot;)));
&lt;br /&gt;

&lt;br /&gt;
DropDownList ddl = ((DropDownList)(objCtrl.FindControl(&amp;quot;Id of the Dropdownlist control in the usercontrol&amp;quot;)));
&lt;br /&gt;

&lt;br /&gt;
Response.Write(ddl.SelectedItem.Value);
&lt;br /&gt;

&lt;br /&gt;
Thats it and you can access the value.
&lt;br /&gt;

&lt;br /&gt;
NOTE:  This is not the only way and there are other ways like creating an object of the usercontrol and accessing.  However, this method is relatively simple.
&lt;br /&gt;</description></item></channel></rss>