I need a way to bind multiple drop down lists that are populated based on their parent node.
RootDDL <- child <- grandchild[]
The code looks something similar to
<FormView DataSoureceID="rootDatasource">
<DropDownList ID="RootDLL" AutoPostBack="true">
<!--items-->
</DropDownList>
<DropDownList ID="child" AutoPostBack="true" DataSourceID="ChildDataSource" />
<SqlDataSource ID="ChildDataSource" />
<DropDownList ID="grandchild" DataSourceID="GrandChildDataSource" SelectedValue='<%# Bind('SomeFieldInRootDatasource') %>' />
<SqlDataSource ID="GrandChildDataSource">
<SelectParameters>
<ControlParameter ControlID="child" PropertyName="SelectedValue" />
</SelectParameters>
</SqlDataSource>
<Button Command="Update" />
</FormView>
<SqlDataSource ID="rootDatasource">
<InsertParameters>
<asp:Parameter Name="SomeFieldInRootDatasource" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="SomeFieldInRootDatasource" />
</UpdateParamters>
</SqlDataSource>
Changing the rootDDL works, unfortunately when the Child selectedvalue changes the grand child <%# Bind %> tries to rebind but cannot as it the FormView is no longer acting as a container.
It fails with
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Is there any solution to this problem that will not require me to add event (multiple) handlers?
I ended up creating a
hiddenfieldfor each childdropdownlistthat I then bound with the value I needed. I created a genericindexchange handlerto then update thehiddenfeildwith the desired result. This results in the bound field not being updated by a datasource (avoiding the rebind system call that was causing the issue in the first place).Not sure if this is the best solution but it should work for most cases.