Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to select items in CascadingDropDown from Code?

$
0
0

Good afternoon,

My problem is that I have 3 dropdown list :

Parent Dropdown List : contain Component Family Name

<asp:DropDownList ID="ddlComponentFamily" runat="server"
AppendDataBoundItems="True" AutoPostBack="True"
DataSourceID="objDSComponentFamily" DataTextField="ComponentFamilyName"
DataValueField="ComponentFamilyID"
onselectedindexchanged="ddlComponentFamily_SelectedIndexChanged">
<asp:ListItem Value="-1">-- Component Family --</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="objDSComponentFamily" runat="server"
SelectMethod="GetComponentFamily" TypeName="CMMS.DAL.ComponentFamilyFactory">
</asp:ObjectDataSource>

Cascarding DropdownList : contain Component Name base on Component Family Name selected

<asp:DropDownList ID="ddlComponent" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlComponent_SelectedIndexChanged">
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="ccdComponent" runat="server"
Category="Component" Enabled="True" LoadingText="Loading List..."
ParentControlID="ddlComponentFamily" PromptText="--Component--"
ServiceMethod="GetComponentServices"
ServicePath="~/Common/Webservices/ComponentService.asmx"
TargetControlID="ddlComponent" UseContextKey="True">
</ajaxToolkit:CascadingDropDown>

Alternative Select DropDownList : contain all ComponentID name

<asp:DropDownList ID="ddlComponentByID" runat="server"
AppendDataBoundItems="True" AutoPostBack="True"
DataSourceID="objDSComponentByID" DataTextField="ComponentID"
DataValueField="ComponentID"
onselectedindexchanged="ddlComponentByID_SelectedIndexChanged">
<asp:ListItem Value="-1">-- Component ID --</asp:ListItem>
</asp:DropDownList>
<asp:ObjectDataSource ID="objDSComponentByID" runat="server"
SelectMethod="GetActiveComponent" TypeName="CMMS.DAL.ComponentFactory">
</asp:ObjectDataSource>

Normally when I click on an item in Parent Dropdown List[Component Family Name], the list of items[Component Name] in Cascarding DropdownList will fill up from WebService[ComponentService.asmx] base on Component Family Name value. Once I click on an item in Cascarding DropdownList[Component Name], the same ComponentID will be chosen on Alternative Select DropDownList.

What I would like to do is that, when I select an item on Alternative Select DropDownList, I want the linked item in [Component Name] in Cascarding DropdownList andParent Dropdown List[Component Family Name] are also selected.

I have programmed with the following statement on ddlComponentByID_SelectedIndexChanged

Component objComponent = (Component)_objCom.GetActiveComponentByID(ddlComponentByID.SelectedValue)[0];
ddlComponentFamily.SelectedValue = objComponent.ComponentFamilyID.ToString();

ddlComponent.SelectedValue = objComponent.ComponentID;


And when I select an item in Alternative Select DropDownList,  I got the following error: 

'ddlComponent' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Could you please guide me how to solve this problem?

Best regards,

Veasna


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>