Passing dropDownList SelectedValue by ControlParameter

It seems difficult to retrieve the data from a dropDownList when using UpdateParameters inside an ObjectDataSource. All I get in return is 'NULL'...

My example where I have a dropDownList which has its ListItems created by an init function in addition to a default listItem called "Default":
<asp:DropDownList OnInit="DropDownCreated" ID="ddlDropWhere" runat="server" Width="200">
     <asp:ListItem Text="Default" Value="" />

This should be passed by the objectDataSourc by its UpdateParameters:
     <asp:ControlParameter Name="dropWhere" controlID="ctl00$ContentPlaceHolder2$FormView1$ddlDropWhere" PropertyName="SelectedValue" Type="String" />

Further my BLL (which eventually saves the data to my database):
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool Save(String dropWhere, ...)

What have I missed?
(My project is ASP.NET C#.)
Who is Participating?
Are you sure that values are being assigned to your list items? For example, in the above code, your "Default" item has a value of "" which is converted to NULL unless you set the ConvertEmptyStringToNull (not sure on exact name of this attribue off the top of my head but it's close to this) to false.
why are you using client id in your control parameters? can't you use the normal server side id of the dropdownlist?
wahoooAuthor Commented:
The ControlID="ctl00$ContentPlaceHolder2$FormView1$ddlDropWhere" is a necessity to avoid this:
Could not find control 'ddlDropWhere' in ControlParameter 'dropWhere'.

Which is the result of setting ControlID="ddlDropWhere".
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

wahoooAuthor Commented:
I have tested by sending the SelectedValue to a function in my aspx.cs-file, and it returns correct values according to my chosen item.

This problem is really bugging me now, as I have tried for some hours (!!) to fix it.
Any help and advice is highly appreciated.
wahoooAuthor Commented:
It seems you are correct..
I had put this out on hold in order to make some progress on my other work, and now I tested it again and the problem seems to be whatever item I select, the form/dropDownList only returns with the first item. I.e. the SelectedIndex is always 0, and therefore the SelectedValue is "" or "NULL" when it is passed on.

How can I make my DropDownList pass on the item which is actually selected?
wahoooAuthor Commented:
Thanks for all your help.
In the end my initial code was correct and my fault actually lay hidden between somewhere:
Inside my Page_Load(..) I did FormView1.DataBind(); which reset the edits done in the form and hence set the value of my selectedIndex to 0.

Glad I found the error in the end though... :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.