Dynamically loading a dropdownlist in Detailview

Dynamically loading a dropdownlist in Detailview

Old forum URL: forums.lhotka.net/forums/t/707.aspx


AFSegovia posted on Monday, July 24, 2006

Hello,

 I have a detailview control, which contains two dropdownlists. If I choose a value from the first dropdown the next needs to be loaded with values. I'm using name value list.

 So far, I haven't been successful reloading the second dropdownlist.

Does anyone know how to do this?

I'm using asp 2.0

 

Thanks in advance

 

fabiousa7 replied on Monday, October 02, 2006

Hi, I am having the exact same problem, did you find a solution for your problem yet?

Is so would you be kind to share it?

Anyone else out there would please comment...

 

Fabio

RockfordLhotka replied on Monday, October 02, 2006

I don't know the specific answer, but in general what you need to do is get the first drop-down to do a postback. In the postback handler (click event?), you need to call DataBind - probably on the DetailsView itself - to force rebinding of the control. That will trigger the SelectObject events to fire for your data source controls, and should allow reloading of the data.

Unless, of course, DetailsView is being "helpful" by caching the drop-down contents for you, so the SelectObject events don't fire - in which case I don't know what you'd do...

fabiousa7 replied on Tuesday, October 03, 2006

Rocky, thanks you for your sujection. I tried that aproach and i think i was getting close to it, but i couldnt consisting selected values through postbacks...

I researched about his online and all the samples I found were using <SelectParameters> wich csla.DataSource does not support.

I am not very experienced with web control's and their binding events, so im having a really hard time solving this. 

Would anyone else any more ideas to help?

 

Thanks,

Fabio

adamnationx replied on Thursday, July 24, 2008

Is there a way to rebind the DropDownList itself? I try calling DataBind() on the second dropdownlist when the first dropdownlist's selectedindex is changed, but I get the following runtime error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

when I try to call the DataBind() method. Both of these dropdownlists are contained within a databound formview and they are both populated from read-only business list data sources. I don't want to rebind the entire formview.... I just want to re-call the selectobject method for the second dropdownlist's datasource. The only way I've been able to get that to happen has been to rebind the entire FormView, but this causes me to lose all my changes (including the newly selected value in the first dropdownlist, which is the whole point for re-selecting the second dropdownlist's values anyway!)

Any advice would be greatly appreciated... I'm stuck!

decius replied on Thursday, July 24, 2008

yeah, I ran into that a while back.  What you can do is call YourDetailsViewID.UpdateItem(false); on the SelectedIndexChanged event for the DropDownList.  This ends up firing the ExecuteUpdate causing the OnSelectObject event in the detailsView CslaDataSource to refire, thus updating the DetailsView.

And yes, you'll need postback enabled for the DropDownList..  Haven't found out a good way to avoid that yet. 

Copyright (c) Marimer LLC