Setting the target and parent dropdown values from a DB when using CascadingDropDown

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-03-24T11:36:53Z Indexed on 2010/03/24 11:43 UTC
Read the original article Hit count: 433

Hi,

I have two dropdown lists with Cascading Dropdown, in the usual fashion:

<asp:DropDownList ID="DropDownListIndustry" runat="server" 
    DataSourceID="SqlDataSourceIndustries" DataTextField="name" DataValueField="industry_id" AppendDataBoundItems="    
<asp:ListItem Text="(Please Select)" Value="-1" />
</asp:DropDownList> &nbsp;&nbsp; 
<ajax:CascadingDropDown ID="CascadingDropDownIndustry" runat="server"
    ParentControlID="DropDownListIndustry" TargetControlID="DropDownListSubIndustry" 
    ServicePath="AjaxDataProvider.asmx" ServiceMethod="GetSubIndustry" 
    Category="SubIndustry" />
<asp:DropDownList ID="DropDownListSubIndustry" runat="server"/>   

No surprises there. However, I sometimes want to set the values of the parent and target from a DB (I want to default them, based on a code entered by the user; the whole thing is wrapped in an update panel). So if the user keys in ABC, I look up ABC in the DB and default the Parent DropDown to ID 10 and Child DropDown to ID 101.

However, this fails because the child has no items when the server side code runs (the web script method hasn't run, because the content of the parent dd wasn't changed on the client side)

Does anybody know how to work around this?

Thanks for any help!

Ryan

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about dropdownlist