<?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>Data Presentation Controls</title><link>http://forums.asp.net/24.aspx</link><description>ASP.NET data-bound controls such as the DataGrid, DataList, GridView, FormView, DetailsView, and Repeater Controls.  &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=23&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/3424485.aspx</link><pubDate>Fri, 25 Sep 2009 04:18:34 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3424485</guid><dc:creator>altafkhatri@hotmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3424485.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=3424485</wfw:commentRss><description>&lt;p&gt;If this is ASP.NET MVC dropdownlist then please refer to this article:&lt;/p&gt;&lt;p&gt;http://www.altafkhatri.com/Technical/How_to_bind_IList_with_MVC_Dropdownlist_box&lt;/p&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/913910.aspx</link><pubDate>Tue, 03 May 2005 00:57:55 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:913910</guid><dc:creator>h8899</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/913910.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=913910</wfw:commentRss><description>&lt;P&gt;Dear Sir,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can we catch the exception on code behind?&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BLOCKQUOTE&gt;&lt;table width="85%"&gt;&lt;tr&gt;&lt;td class="txt4"&gt;&lt;img src="/Themes/default/images/icon-quote.gif"&gt;&amp;nbsp;&lt;strong&gt;Fredrik N wrote:&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="quoteTable"&gt;&lt;table width="100%"&gt;&lt;tr&gt;&lt;td width="100%" valign="top" class="txt4"&gt;Take a look at the following Example (It uses the Northwind database) that will get data from one data-source control and also fill a DropDownList by using another data-source control. The SelectedValue is bound to the ContactTitle value returned form the first data-source control. The value bind to the DropDownList SelectedValue, must be located within the DropDownList, if not an exception will be thrown: &lt;CODE&gt;&lt;/P&gt;

&lt;DIV&gt;&lt;BR&gt;" UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [ContactTitle] = @ContactTitle WHERE [CustomerID] = @original_CustomerID"&gt;&lt;/DIV&gt;&lt;/CODE&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/BLOCKQUOTE&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/796828.aspx</link><pubDate>Wed, 12 Jan 2005 14:08:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:796828</guid><dc:creator>gregkats</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/796828.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=796828</wfw:commentRss><description>I have finally found the problem I have been having in this process.
&lt;br /&gt;

&lt;br /&gt;
Here is what I finally came up with.  If, during Page_Load, I use either of the following lines I get the error mentioned below about binding the selected item:
&lt;br /&gt;

&lt;br /&gt;
&lt;pre&gt;
&lt;br /&gt;
this.FormView1.FindControl(&amp;quot;SomeFieldName&amp;quot;).Focus();
&lt;br /&gt;
this.Form.DefaultButton = ((ImageButton)this.FormView1.FindControl(&amp;quot;SomeButtonName&amp;quot;)).UniqueID;
&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;

&lt;br /&gt;
If I comment out those two lines the bind of the page works correctly.  If I don't have a DropDownList that I need to bind the SelectedValue on the page I can use those lines just fine.  I don't know why this is a problem.  But it happens 100% of the time for me.  I don't know if it's a problem with anything other than the ObjectDataSource or Not.
&lt;br /&gt;

&lt;br /&gt;
Again this is the November CTP.</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795687.aspx</link><pubDate>Tue, 11 Jan 2005 13:56:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795687</guid><dc:creator>gregkats</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795687.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795687</wfw:commentRss><description>OK.  
&lt;br /&gt;

&lt;br /&gt;
So the lesson learned here is the DataSource Control for binding the SelectedItem needs to be inside the Template of the FormView Control and the DataSource Control for the FormView Control needs to be outside the FormView Control.
&lt;br /&gt;

&lt;br /&gt;
It works now.
&lt;br /&gt;

&lt;br /&gt;
Thanks</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795664.aspx</link><pubDate>Tue, 11 Jan 2005 13:14:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795664</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795664.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795664</wfw:commentRss><description>It actually work, because the other data source is located whiten the template of the FormView. But I should have different name, to make it easier to identity the two data source. I didn't care about that when I created the example for you.</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795663.aspx</link><pubDate>Tue, 11 Jan 2005 13:07:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795663</guid><dc:creator>gregkats</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795663.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795663</wfw:commentRss><description>Fredrik,
&lt;br /&gt;

&lt;br /&gt;
Thanks for the code!  The only question I have is I don't understand how the code can work as posted because you have two ObjectDataSource controls named ObjectDataSource1.  I assume that is just a typo.
&lt;br /&gt;

&lt;br /&gt;
Thanks
&lt;br /&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795648.aspx</link><pubDate>Tue, 11 Jan 2005 12:57:38 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795648</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795648.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795648</wfw:commentRss><description>Here is a working example, that uses the ObejctDataSource:
&lt;br /&gt;

&lt;br /&gt;
Default.aspx
&lt;br /&gt;

&lt;br /&gt;
&lt;pre&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; %&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)
&lt;br /&gt;
    {
&lt;br /&gt;
        if (Request.QueryString[&amp;quot;Mode&amp;quot;] == &amp;quot;Insert&amp;quot;)
&lt;br /&gt;
            FormView1.DefaultMode = FormViewMode.Insert;
&lt;br /&gt;
        else
&lt;br /&gt;
            FormView1.DefaultMode = FormViewMode.ReadOnly;
&lt;br /&gt;
    }    
&lt;br /&gt;
&amp;lt;/script&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; &amp;gt;
&lt;br /&gt;
&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
    &amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;
&lt;br /&gt;
&amp;lt;/head&amp;gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;
&lt;br /&gt;
    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
    &amp;lt;div&amp;gt;
&lt;br /&gt;
    &amp;lt;asp:FormView DataSourceID=&amp;quot;ObjectDataSource1&amp;quot;
&lt;br /&gt;
                ID=&amp;quot;FormView1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
                &amp;lt;InsertItemTemplate&amp;gt;
&lt;br /&gt;
                    CustomerName:
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;CustomerNameTextBox&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;CustomerName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;
&lt;br /&gt;
                    CustomerTitle:
&lt;br /&gt;
                    &amp;lt;asp:DropDownList SelectedValue='&amp;lt;%# Bind(&amp;quot;CustomerTitle&amp;quot;) %&amp;gt;' DataSourceID=&amp;quot;ObjectDataSource1&amp;quot; ID=&amp;quot;DropDownList1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:DropDownList&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:ObjectDataSource ID=&amp;quot;ObjectDataSource1&amp;quot; runat=&amp;quot;server&amp;quot; SelectMethod=&amp;quot;GetAllTitles&amp;quot;
&lt;br /&gt;
                        TypeName=&amp;quot;CustomerRepository&amp;quot;&amp;gt;&amp;lt;/asp:ObjectDataSource&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:LinkButton CausesValidation=&amp;quot;True&amp;quot; CommandName=&amp;quot;Insert&amp;quot; ID=&amp;quot;InsertButton&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;br /&gt;
                        Text=&amp;quot;Insert&amp;quot;&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
                    &amp;amp;nbsp;&amp;lt;asp:LinkButton CausesValidation=&amp;quot;False&amp;quot; CommandName=&amp;quot;Cancel&amp;quot; ID=&amp;quot;InsertCancelButton&amp;quot;
&lt;br /&gt;
                        runat=&amp;quot;server&amp;quot; Text=&amp;quot;Cancel&amp;quot;&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
                &amp;lt;/InsertItemTemplate&amp;gt;
&lt;br /&gt;
                &amp;lt;ItemTemplate&amp;gt;
&lt;br /&gt;
                    CustomerName:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;CustomerNameLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Eval(&amp;quot;CustomerName&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    CustomerID:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;CustomerIDLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    CustomerTitle:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;CustomerTitleLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Eval(&amp;quot;CustomerTitle&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:LinkButton CausesValidation=&amp;quot;False&amp;quot; CommandName=&amp;quot;New&amp;quot; ID=&amp;quot;InsertButton&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;br /&gt;
                        Text=&amp;quot;Insert&amp;quot;&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
                &amp;lt;/ItemTemplate&amp;gt;
&lt;br /&gt;
            &amp;lt;/asp:FormView&amp;gt;
&lt;br /&gt;
        &amp;lt;asp:ObjectDataSource DataObjectTypeName=&amp;quot;Customer&amp;quot; ID=&amp;quot;ObjectDataSource1&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;br /&gt;
            SelectMethod=&amp;quot;GetAll&amp;quot;
&lt;br /&gt;
            TypeName=&amp;quot;CustomerRepository&amp;quot;
&lt;br /&gt;
            InsertMethod=&amp;quot;Insert&amp;quot;&amp;gt;&amp;lt;/asp:ObjectDataSource&amp;gt;
&lt;br /&gt;
        &amp;amp;nbsp;
&lt;br /&gt;
    &amp;lt;/div&amp;gt;
&lt;br /&gt;
    &amp;lt;/form&amp;gt;
&lt;br /&gt;
&amp;lt;/body&amp;gt;
&lt;br /&gt;
&amp;lt;/html&amp;gt;
&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
CustomerRespository.cs
&lt;br /&gt;
&lt;pre&gt;
&lt;br /&gt;
public class CustomerRepository
&lt;br /&gt;
{
&lt;br /&gt;
	public CustomerRepository()
&lt;br /&gt;
	{
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public IList&amp;lt;Customer&amp;gt; GetAll()
&lt;br /&gt;
	{
&lt;br /&gt;
		IList&amp;lt;Customer&amp;gt; customers = new List&amp;lt;Customer&amp;gt;();
&lt;br /&gt;

&lt;br /&gt;
		customers.Add(new Customer(1, &amp;quot;Fredrik&amp;quot;, &amp;quot;Developer&amp;quot;));
&lt;br /&gt;
		customers.Add(new Customer(2, &amp;quot;Johan&amp;quot;, &amp;quot;Developer&amp;quot;));
&lt;br /&gt;
		customers.Add(new Customer(3, &amp;quot;Lovisa&amp;quot;, &amp;quot;Product Manager&amp;quot;));
&lt;br /&gt;
		customers.Add(new Customer(4, &amp;quot;Anna&amp;quot;, &amp;quot;Program Manager&amp;quot;));
&lt;br /&gt;

&lt;br /&gt;
		return customers;
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public void Insert(Customer customer)
&lt;br /&gt;
	{
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public void Insert(string customerName, string customerTitle)
&lt;br /&gt;
	{
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public string[] GetAllTitles()
&lt;br /&gt;
	{
&lt;br /&gt;
		return new string[] { &amp;quot;Developer&amp;quot;, &amp;quot;Product Manager&amp;quot;, &amp;quot;Program Manager&amp;quot; };
&lt;br /&gt;
	}
&lt;br /&gt;
}
&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
Customer.cs
&lt;br /&gt;
&lt;pre&gt;
&lt;br /&gt;
public class Customer
&lt;br /&gt;
{
&lt;br /&gt;
	private int _customerId;
&lt;br /&gt;
	private string _customerName;
&lt;br /&gt;
	private string _customerTitle;
&lt;br /&gt;
	
&lt;br /&gt;
	public Customer()
&lt;br /&gt;
	{
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public Customer(int customerId, string customerName, string customerTitle)
&lt;br /&gt;
	{
&lt;br /&gt;
		this._customerId = customerId;
&lt;br /&gt;
		this._customerName = customerName;
&lt;br /&gt;
		this.CustomerTitle = customerTitle;
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public int CustomerID
&lt;br /&gt;
	{
&lt;br /&gt;
		get { return this._customerId; }
&lt;br /&gt;
		internal set { this._customerId = value; }
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public string CustomerName
&lt;br /&gt;
	{
&lt;br /&gt;
		get { return this._customerName; }
&lt;br /&gt;
		set { this._customerName = value; }
&lt;br /&gt;
	}
&lt;br /&gt;

&lt;br /&gt;
	public string CustomerTitle
&lt;br /&gt;
	{
&lt;br /&gt;
		get { return this._customerTitle; }
&lt;br /&gt;
		set { this._customerTitle = value; }
&lt;br /&gt;
	}
&lt;br /&gt;
}
&lt;br /&gt;
&lt;/pre&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795614.aspx</link><pubDate>Tue, 11 Jan 2005 12:14:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795614</guid><dc:creator>gregkats</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795614.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795614</wfw:commentRss><description>Phuff,
&lt;br /&gt;

&lt;br /&gt;
I don't think the InsertItemTemplate really has anything to do with the problem.  It doesn't work even if it's in EditMode.  Besides that, the point of Binding form elements is so the FormView will handle the Update/Insert calls back to the datasource correctly.  And Fredrik and others on this message board say they are getting it to work on SQLDataSources.
&lt;br /&gt;

&lt;br /&gt;
Fredrik,
&lt;br /&gt;

&lt;br /&gt;
The only difference I see in the code you posted and what I posted is you are using SQLDataSource and I am using ObjectDataSource.  I have to assume there is an issue with binding the SelectedValue in an ObjectDataSource.  If you see any other differences I would appreciate hearing about it.
&lt;br /&gt;

&lt;br /&gt;
In the CodeFile, Page_Load method, I check for an ID in the QueryString and switch the mode of the FormView to Edit or Insert as appropriate.
&lt;br /&gt;

&lt;br /&gt;
TIA</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795441.aspx</link><pubDate>Tue, 11 Jan 2005 05:26:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795441</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795441.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795441</wfw:commentRss><description>The following example uses the InsertItemTemplate, where the Bind expression is used on DropDownList SelectedValue to make sure the selected value is passed to into input parameter. The code uses the SqlDataSource control, but this should work for the ObjectDataSOurce control also.
&lt;br /&gt;

&lt;br /&gt;
&lt;pre&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;Default.aspx.cs&amp;quot; Inherits=&amp;quot;Default_aspx&amp;quot; %&amp;gt;
&lt;br /&gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;
&lt;br /&gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&amp;gt;
&lt;br /&gt;
&amp;lt;head id=&amp;quot;Head1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
    &amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;
&lt;br /&gt;
&amp;lt;/head&amp;gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;
&lt;br /&gt;
    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
        &amp;lt;div&amp;gt;
&lt;br /&gt;
            &amp;lt;asp:FormView DataKeyNames=&amp;quot;CustomerID&amp;quot; DefaultMode=Insert DataSourceID=&amp;quot;SqlDataSource1&amp;quot; ID=&amp;quot;FormView1&amp;quot;
&lt;br /&gt;
                runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
                &amp;lt;InsertItemTemplate&amp;gt;
&lt;br /&gt;
                    CustomerID:
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;CustomerID&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;CustomerID&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;
&lt;br /&gt;
                    CompanyName:
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;CompanyNameTextBox&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;CompanyName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;
&lt;br /&gt;
                    ContactName:
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;ContactNameTextBox&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;
&lt;br /&gt;
                    ContactTitle:
&lt;br /&gt;
                    &amp;lt;asp:DropDownList SelectedValue='&amp;lt;%# Bind(&amp;quot;ContactTitle&amp;quot;) %&amp;gt;' DataSourceID=&amp;quot;SqlDataSource1&amp;quot; DataTextField=&amp;quot;ContactTitle&amp;quot; DataValueField=&amp;quot;ContactTitle&amp;quot;
&lt;br /&gt;
                        ID=&amp;quot;DropDownList1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:DropDownList&amp;gt;&amp;lt;asp:SqlDataSource ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;quot;
&lt;br /&gt;
                        ID=&amp;quot;SqlDataSource1&amp;quot; runat=&amp;quot;server&amp;quot; SelectCommand=&amp;quot;SELECT DISTINCT [ContactTitle] FROM [Customers]&amp;quot;&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:SqlDataSource&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:LinkButton CausesValidation=&amp;quot;True&amp;quot; CommandName=&amp;quot;Insert&amp;quot; ID=&amp;quot;InsertButton&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;br /&gt;
                        Text=&amp;quot;Insert&amp;quot;&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
                    &amp;amp;nbsp;&amp;lt;asp:LinkButton CausesValidation=&amp;quot;False&amp;quot; CommandName=&amp;quot;Cancel&amp;quot; ID=&amp;quot;CancelButton&amp;quot;
&lt;br /&gt;
                        runat=&amp;quot;server&amp;quot; Text=&amp;quot;Cancel&amp;quot;&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
                &amp;lt;/InsertItemTemplate&amp;gt;
&lt;br /&gt;
                &amp;lt;ItemTemplate&amp;gt;
&lt;br /&gt;
                    CustomerID:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;CustomerIDLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    CompanyName:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;CompanyNameLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;CompanyName&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    ContactName:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;ContactNameLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactName&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    ContactTitle:
&lt;br /&gt;
                    &amp;lt;asp:Label ID=&amp;quot;ContactTitleLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactTitle&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                    &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                    &amp;lt;br /&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:Button ID=&amp;quot;EditButton&amp;quot; runat=&amp;quot;server&amp;quot; CommandName=&amp;quot;Edit&amp;quot; Text=&amp;quot;Edit&amp;quot; /&amp;gt;
&lt;br /&gt;
                &amp;lt;/ItemTemplate&amp;gt;
&lt;br /&gt;
            &amp;lt;/asp:FormView&amp;gt;
&lt;br /&gt;
            &amp;lt;asp:SqlDataSource ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;quot;
&lt;br /&gt;
                ID=&amp;quot;SqlDataSource1&amp;quot; runat=&amp;quot;server&amp;quot; SelectCommand=&amp;quot;SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]&amp;quot;
&lt;br /&gt;
                InsertCommand=&amp;quot;INSERT INTO [Customers]  ([CustomerID],[CompanyName], [ContactName], [ContactTitle]) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle)&amp;quot;&amp;gt;
&lt;br /&gt;
            &amp;lt;/asp:SqlDataSource&amp;gt;
&lt;br /&gt;
        &amp;lt;/div&amp;gt;
&lt;br /&gt;
    &amp;lt;/form&amp;gt;
&lt;br /&gt;
&amp;lt;/body&amp;gt;
&lt;br /&gt;
&amp;lt;/html&amp;gt;
&lt;br /&gt;
&lt;/pre&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/795142.aspx</link><pubDate>Mon, 10 Jan 2005 21:42:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:795142</guid><dc:creator>phuff</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/795142.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=795142</wfw:commentRss><description>You're getting this error because you have bindings (Bind statements, Evals, etc.) in your InsertItemTemplate of the FormView.  FormView isn't databound in Insert mode (there's no current data item in Insert mode- you're attempting to create the item, so you get just un-databound controls) so the control doesn't have an item to reference for the databindings.
&lt;br /&gt;

&lt;br /&gt;
Are you trying to put default values into the Insert form?  You should just set the Text and SelectedIndex properties directly instead of using a data item.  If you need to use a record from your database as the default value source, I advise that you handle the OnModeChanging, see if it's changing to Insert, and copy your default record to a new record in your database, then change the NewMode to edit the new record.
&lt;br /&gt;

&lt;br /&gt;
If you don't need default values in your Insert form, just remove the bindings and everything should work fine.
&lt;br /&gt;

&lt;br /&gt;
Hope this helps...</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/794843.aspx</link><pubDate>Mon, 10 Jan 2005 17:41:03 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:794843</guid><dc:creator>gregkats</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/794843.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=794843</wfw:commentRss><description>Fredrik,
&lt;br /&gt;

&lt;br /&gt;
I am trying to do the same thing with ObjectDataSources instead of SQLDataSources.  But I keep getting the error &amp;quot;Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.&amp;quot;
&lt;br /&gt;

&lt;br /&gt;
It only occurs when I try to Bind the SelectedValue of a DropDownList.
&lt;br /&gt;

&lt;br /&gt;
[code]
&lt;br /&gt;
&amp;lt;asp:Content ID=&amp;quot;Content1&amp;quot; ContentPlaceHolderID=&amp;quot;Main&amp;quot; Runat=&amp;quot;Server&amp;quot;&amp;gt;
&lt;br /&gt;
    &amp;lt;asp:FormView DataSourceID=&amp;quot;ObjectDataSource1&amp;quot; ID=&amp;quot;FormView1&amp;quot; runat=&amp;quot;server&amp;quot; Caption=&amp;quot;Contact&amp;quot; DefaultMode=&amp;quot;Insert&amp;quot; &amp;gt;
&lt;br /&gt;
        &amp;lt;InsertItemTemplate&amp;gt;
&lt;br /&gt;
        &amp;lt;table cellpadding=&amp;quot;0&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    First Name:
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;txtContactFirstName&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactFirstName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    Last Name:
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;txtContactLastName&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactLastName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    Company:
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:DropDownList ID=&amp;quot;ddlCompany&amp;quot; DataSourceID=&amp;quot;ObjectDataSource2&amp;quot; SelectedValue='&amp;lt;%# Bind(&amp;quot;ContactCompanyID&amp;quot;) %&amp;gt;' DataValueField=&amp;quot;CompanyID&amp;quot; DataTextField=&amp;quot;CompanyName&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td colspan=&amp;quot;2&amp;quot; align=&amp;quot;Center&amp;quot;&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:ImageButton ID=&amp;quot;btnSave&amp;quot; CommandName=&amp;quot;Insert&amp;quot; runat=&amp;quot;server&amp;quot; SkinID=&amp;quot;add&amp;quot; /&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
        &amp;lt;/table&amp;gt;
&lt;br /&gt;
        &amp;lt;/InsertItemTemplate&amp;gt;
&lt;br /&gt;
        &amp;lt;EditItemTemplate&amp;gt;
&lt;br /&gt;
        &amp;lt;table cellpadding=&amp;quot;0&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    First Name:
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;txtContactFirstName&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactFirstName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    Last Name:
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:TextBox ID=&amp;quot;txtContactLastName&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactLastName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    Company:
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
                &amp;lt;td&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:DropDownList ID=&amp;quot;ddlCompany&amp;quot; DataSourceID=&amp;quot;ObjectDataSource2&amp;quot; SelectedValue='&amp;lt;%# Bind(&amp;quot;ContactCompanyID&amp;quot;) %&amp;gt;' DataValueField=&amp;quot;CompanyID&amp;quot; DataTextField=&amp;quot;CompanyName&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
            &amp;lt;tr&amp;gt;
&lt;br /&gt;
                &amp;lt;td colspan=&amp;quot;2&amp;quot; align=&amp;quot;Center&amp;quot;&amp;gt;
&lt;br /&gt;
                    &amp;lt;asp:ImageButton ID=&amp;quot;btnSave&amp;quot; runat=&amp;quot;server&amp;quot; CommandName=&amp;quot;Update&amp;quot; SkinID=&amp;quot;save&amp;quot; /&amp;gt;&amp;amp;nbsp;&amp;lt;asp:ImageButton CausesValidation=&amp;quot;false&amp;quot; ID=&amp;quot;btnDelete&amp;quot; CommandName=&amp;quot;Delete&amp;quot; runat=&amp;quot;server&amp;quot; SkinID=&amp;quot;delete&amp;quot; OnClientClick=&amp;quot;if (!confirm('Are You Sure You Want To Delete This Item')){return false}&amp;quot;/&amp;gt;
&lt;br /&gt;
                &amp;lt;/td&amp;gt;
&lt;br /&gt;
            &amp;lt;/tr&amp;gt;
&lt;br /&gt;
        &amp;lt;/table&amp;gt;
&lt;br /&gt;
        &amp;lt;/EditItemTemplate&amp;gt;
&lt;br /&gt;
    &amp;lt;/asp:FormView&amp;gt;
&lt;br /&gt;
    &amp;lt;asp:ObjectDataSource ID=&amp;quot;ObjectDataSource1&amp;quot; runat=&amp;quot;server&amp;quot; SelectMethod=&amp;quot;Retrieve&amp;quot; DeleteMethod=&amp;quot;Delete&amp;quot; InsertMethod=&amp;quot;Insert&amp;quot; UpdateMethod=&amp;quot;Update&amp;quot; TypeName=&amp;quot;Contact&amp;quot;&amp;gt;&amp;lt;/asp:ObjectDataSource&amp;gt;
&lt;br /&gt;
    &amp;lt;asp:ObjectDataSource ID=&amp;quot;ObjectDataSource2&amp;quot; runat=&amp;quot;server&amp;quot; SelectMethod=&amp;quot;ListAll&amp;quot; TypeName=&amp;quot;Companies&amp;quot;&amp;gt;&amp;lt;/asp:ObjectDataSource&amp;gt;
&lt;br /&gt;
&amp;lt;/asp:Content&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
[/code]
&lt;br /&gt;

&lt;br /&gt;
Have you been able to get this to work or is this a Bug with the ObjectDataSource code?  I am using November CTP.
&lt;br /&gt;

&lt;br /&gt;
TIA</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/794023.aspx</link><pubDate>Sun, 09 Jan 2005 16:58:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:794023</guid><dc:creator>weiwei99</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/794023.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=794023</wfw:commentRss><description>Fredrik,
&lt;br /&gt;

&lt;br /&gt;
It works!
&lt;br /&gt;
Thank you very much.
&lt;br /&gt;
You helped me solved two problems.
&lt;br /&gt;
Thanks again.
&lt;br /&gt;

&lt;br /&gt;

&lt;br /&gt;

&lt;br /&gt;
Regards,
&lt;br /&gt;

&lt;br /&gt;
Henry
&lt;br /&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/793978.aspx</link><pubDate>Sun, 09 Jan 2005 15:10:12 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:793978</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/793978.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=793978</wfw:commentRss><description>Take a look at the following Example (It uses the Northwind database) that will get data from one data-source control and also fill a DropDownList by using another data-source control. The SelectedValue is bound to the ContactTitle value returned form the first data-source control. The value bind to the DropDownList SelectedValue, must be located within the DropDownList, if not an exception will be thrown:
&lt;br /&gt;
&lt;pre&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot;  CodeFile=&amp;quot;Default.aspx.cs&amp;quot; Inherits=&amp;quot;Default_aspx&amp;quot; %&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; &amp;gt;
&lt;br /&gt;
&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
    &amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;
&lt;br /&gt;
&amp;lt;/head&amp;gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;
&lt;br /&gt;
    &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
    &amp;lt;div&amp;gt;
&lt;br /&gt;
        &amp;lt;asp:FormView DataKeyNames=&amp;quot;CustomerID&amp;quot; DataSourceID=&amp;quot;SqlDataSource1&amp;quot; ID=&amp;quot;FormView1&amp;quot;
&lt;br /&gt;
            runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
            &amp;lt;EditItemTemplate&amp;gt;
&lt;br /&gt;
                CustomerID:
&lt;br /&gt;
                &amp;lt;asp:Label ID=&amp;quot;CustomerIDLabel1&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                &amp;lt;br /&amp;gt;
&lt;br /&gt;
                CompanyName:
&lt;br /&gt;
                &amp;lt;asp:TextBox ID=&amp;quot;CompanyNameTextBox&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;CompanyName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;
&lt;br /&gt;
                ContactName:
&lt;br /&gt;
                &amp;lt;asp:TextBox ID=&amp;quot;ContactNameTextBox&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactName&amp;quot;) %&amp;gt;'&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;br /&amp;gt;
&lt;br /&gt;
                ContactTitle:
&lt;br /&gt;
                &amp;lt;asp:DropDownList SelectedValue='&amp;lt;%# Bind(&amp;quot;ContactTitle&amp;quot;) %&amp;gt;' DataSourceID=&amp;quot;SqlDataSource1&amp;quot; DataTextField=&amp;quot;ContactTitle&amp;quot; DataValueField=&amp;quot;ContactTitle&amp;quot;
&lt;br /&gt;
                    ID=&amp;quot;DropDownList1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&lt;br /&gt;
                &amp;lt;/asp:DropDownList&amp;gt;&amp;lt;asp:SqlDataSource ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;quot;
&lt;br /&gt;
                    ID=&amp;quot;SqlDataSource1&amp;quot; runat=&amp;quot;server&amp;quot; SelectCommand=&amp;quot;SELECT DISTINCT [ContactTitle] FROM [Customers]&amp;quot;&amp;gt;
&lt;br /&gt;
                &amp;lt;/asp:SqlDataSource&amp;gt;
&lt;br /&gt;
                &amp;lt;br /&amp;gt;
&lt;br /&gt;
                &amp;lt;asp:LinkButton CausesValidation=&amp;quot;True&amp;quot; CommandName=&amp;quot;Update&amp;quot; ID=&amp;quot;UpdateButton&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;br /&gt;
                    Text=&amp;quot;Update&amp;quot;&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
                &amp;amp;nbsp;&amp;lt;asp:LinkButton CausesValidation=&amp;quot;False&amp;quot; CommandName=&amp;quot;Cancel&amp;quot; ID=&amp;quot;UpdateCancelButton&amp;quot;
&lt;br /&gt;
                    runat=&amp;quot;server&amp;quot; Text=&amp;quot;Cancel&amp;quot;&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;
&lt;br /&gt;
            &amp;lt;/EditItemTemplate&amp;gt;
&lt;br /&gt;
            &amp;lt;ItemTemplate&amp;gt;
&lt;br /&gt;
                CustomerID:
&lt;br /&gt;
                &amp;lt;asp:Label ID=&amp;quot;CustomerIDLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Eval(&amp;quot;CustomerID&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                &amp;lt;br /&amp;gt;
&lt;br /&gt;
                CompanyName:
&lt;br /&gt;
                &amp;lt;asp:Label ID=&amp;quot;CompanyNameLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;CompanyName&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                &amp;lt;br /&amp;gt;
&lt;br /&gt;
                ContactName:
&lt;br /&gt;
                &amp;lt;asp:Label ID=&amp;quot;ContactNameLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactName&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                &amp;lt;br /&amp;gt;
&lt;br /&gt;
                ContactTitle:
&lt;br /&gt;
                &amp;lt;asp:Label ID=&amp;quot;ContactTitleLabel&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# Bind(&amp;quot;ContactTitle&amp;quot;) %&amp;gt;'&amp;gt;
&lt;br /&gt;
                &amp;lt;/asp:Label&amp;gt;
&lt;br /&gt;
                &amp;lt;br /&amp;gt;
&lt;br /&gt;
                &amp;lt;asp:Button ID=&amp;quot;EditButton&amp;quot; runat=&amp;quot;server&amp;quot; CommandName=&amp;quot;Edit&amp;quot; Text=&amp;quot;Edit&amp;quot; /&amp;gt;
&lt;br /&gt;
            &amp;lt;/ItemTemplate&amp;gt;
&lt;br /&gt;
        &amp;lt;/asp:FormView&amp;gt;
&lt;br /&gt;
        &amp;lt;asp:SqlDataSource ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;&amp;quot;
&lt;br /&gt;
            ID=&amp;quot;SqlDataSource1&amp;quot; runat=&amp;quot;server&amp;quot;
&lt;br /&gt;
            SelectCommand=&amp;quot;SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]&amp;quot;
&lt;br /&gt;
            UpdateCommand=&amp;quot;UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [ContactTitle] = @ContactTitle WHERE [CustomerID] = @original_CustomerID&amp;quot;&amp;gt;
&lt;br /&gt;
            
&lt;br /&gt;
        &amp;lt;/asp:SqlDataSource&amp;gt;
&lt;br /&gt;
    
&lt;br /&gt;
    &amp;lt;/div&amp;gt;
&lt;br /&gt;
    &amp;lt;/form&amp;gt;
&lt;br /&gt;
&amp;lt;/body&amp;gt;
&lt;br /&gt;
&amp;lt;/html&amp;gt;
&lt;br /&gt;
&lt;/pre&gt;</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/793955.aspx</link><pubDate>Sun, 09 Jan 2005 14:23:37 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:793955</guid><dc:creator>weiwei99</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/793955.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=793955</wfw:commentRss><description>Hi Fredrik,
&lt;br /&gt;

&lt;br /&gt;
SelectedValue cannot be set at design time, this is the error message I get if I put in:
&lt;br /&gt;
&amp;lt;asp:DropDownList SelectedValue='&amp;lt;%# Bind(&amp;quot;State&amp;quot;)%&amp;gt;' ....&amp;gt; 
&lt;br /&gt;

&lt;br /&gt;
Error Message:
&lt;br /&gt;
The 'SelectedValue' property can only be set programmatically. It cannot be declared.
&lt;br /&gt;

&lt;br /&gt;
Moreover, a DropDownList (or a ListBox) can only be bound to one datasource.
&lt;br /&gt;
I have to use this datasource to populate the choice item with records from a lookup table.
&lt;br /&gt;
Now, if I want to bind its SelectedValue to another table containing users selection, it seems to be imposssible.
&lt;br /&gt;

&lt;br /&gt;
Am I right?
&lt;br /&gt;

&lt;br /&gt;
Thank you.</description></item><item><title>Re: DropDownList binding SelectedValue</title><link>http://forums.asp.net/thread/793871.aspx</link><pubDate>Sun, 09 Jan 2005 08:20:10 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:793871</guid><dc:creator>Fredrik N</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/793871.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=24&amp;PostID=793871</wfw:commentRss><description>If you use another data-bound control such as the FormView or DetailsView to bind the user's information, you could use the Bind expression to set the SelectedValue based on a value returned from the data-source control that is associated with the FormView or DetailsView control:
&lt;br /&gt;

&lt;br /&gt;
&amp;lt;asp:DropDownList SelectedValue='&amp;lt;%# Bind(&amp;quot;State&amp;quot;)%&amp;gt;' ....&amp;gt;
&lt;br /&gt;

&lt;br /&gt;
The Sate in the example above, is the field returned from the SelectCommand specified for the DetailsView, FormView or other data-bound control.
&lt;br /&gt;</description></item></channel></rss>