I can't figure it out, so please help:
Database tables:
table1 has two columns named id, location and location column will be display in dropdownlist1.
table2 has many columns including a Resource column that i want to display in dropdownlist2 when the user select a name from dropdownlist1, content of dropdownlist2 should dipslay the right choices only. The two tables are linked by id column
Dataconnections queries:
1. select "ID","LOCATION" from "dbo"."ScheduleLocation" as "Location"
2. shape
{select "ID","Resource" from "dbo"."ScheduleResource" as "ScheduleResource"} as "ScheduleResource"
append
({select "ID","LOCATION" from "dbo"."ScheduleLocation" as "ScheduleLocation"}
relate "ID" TO "ID") as "ScheduleLocation"
And here are my event handler:
public void Location_Changed(object sender, XmlEventArgs e)
{
string dataConnectionName = "ScheduleResource";
string dataSourceName = "ScheduleResource";
string ForeignKey = "LOCATION";
string cascadingDropDownDataSourceField = "/my:myFields/my:Resource";
string selectedLocationValue = e.NewValue;
string repeatingNode = "/dfs:myFields/dfs:dataFields/d:ScheduleResource/d:ScheduleLocation";
PopulateCascadingDropDown(selectedLocationValue, dataConnectionName, dataSourceName, repeatingNode, ForeignKey, cascadingDropDownDataSourceField);
}
private void PopulateCascadingDropDown(string selectedLocationValue, string dataConnectionName, string dataSourceName, string repeatingNode,
string ForeignKey, string cascadingDropDownDataSourceField)
{
XPathNavigator xnMain = this.MainDataSource.CreateNavigator();
xnMain.SelectSingleNode(cascadingDropDownDataSourceField,this.NamespaceManager).SetValue(string.Empty);
DataConnection dcSecond = this.DataConnections[dataConnectionName];
dcSecond.Execute();
XPathNavigator xnFD =this.DataSources[dataSourceName].CreateNavigator();
string xPathString = repeatingNode + "[@" + ForeignKey + "!='" + selectedLocationValue + "']";
XPathNodeIterator items = xnFD.Select(xPathString,this.NamespaceManager);
while (items.Count != 0)
{
xnFD.SelectSingleNode(xPathString,
this.NamespaceManager).DeleteSelf();
items = xnFD.Select(xPathString, this.NamespaceManager);
}
}
The problem was, dropdownlist2 always display the entire content regardless what selected in dropdownlist1. Can someone help pointing out the issue? did I implemented correctly? Thank you in advance.