• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4454
  • Last Modified:

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#.)
  • 4
2 Solutions
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".
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.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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... :)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now