Saturday, March 24, 2012

CascadingDropDownlist: How Do I Save the SelectedValue Back To Database

I'm using the AJAX CascadingDropDown extender inside a FormView's InsertItemTemplate.
Question: What is the correct way to save the CascadingDropDown 's selected value back to the database?

I've tried do it by setting the SelectedValue in the CascadingDropDown tag (not the DropDownList) like this:
SelectedValue='<%# Bind("SellerRegionId") %>'

However, when trying to save, this fails with error "Input string was not in a correct format."

I've been able to make it work by setting the Values dictionary in the FormView's ItemInserting() event handler, using the SelectedValue of the DropDownList control (not the extender), as follows:
e.Values["SellerRegionId"] = sellerRegionDropDownList.SelectedValue;

Is this the correct way to do this?

Thanks, in advance, for any help you can give.

Yes the latter should work and in my own opinion personally is more efficient.

No comments:

Post a Comment