Pages

Wednesday, February 29, 2012

Populate Dynamic Dropdown values based on Radio button in the Infopath form 2007






















The below Dataconnection name is TestConn.Create dataconnection in the Infopath form

the List GUIid is {46A48934-00D5-4914-8EF2-E012AD40343C}

http://star:111/sites/pf/_vti_bin/owssvr.dll?Cmd=Display&List={46A48934-00D5-4914-8EF2-E012AD40343C}&XMLDATA=TRUE&noredirect=true

set the dataconnection in the VSTA code

First write the code in the button changed event
--------------------------------------------------------
XPathNavigator root = MainDataSource.CreateNavigator();
// Get the value for the selected department string Filter = "HC";
// Clear the last selected value in the Months drop-down list box root.SelectSingleNode("//my:Months", NamespaceManager).SetValue("");
// Retrieve the data connection bound to the HC radio button FileQueryConnection con = (FileQueryConnection)DataConnections["TestConn"];
// Change the location of the data connection to point the XML file // returned by the owssvr.dll with a filter on department con.FileLocation = @"http://star:111/sites/pf/_vti_bin/owssvr.dll" + "?Cmd=Display&List={46A48934-00D5-4914-8EF2-E012AD40343C}" + "&XMLDATA=TRUE&FilterField1=FName&FilterValue1=" + Filter;
// Query the data connection to fill the Months drop-down list box with items con.Execute();


---------------------------------------------------
Second write the code in the button changed event
----------------------------------------------------
XPathNavigator root = MainDataSource.CreateNavigator();
// Get the value for the selected department string Filter = "NI";
// Clear the last selected value in the Months drop-down list box root.SelectSingleNode("//my:Months", NamespaceManager).SetValue("");
// Retrieve the data connection bound to the NI radio button FileQueryConnection con = (FileQueryConnection)DataConnections["TestConn"];
// Change the location of the data connection to point the XML file // returned by the owssvr.dll with a filter on department con.FileLocation = @"http://star:111/sites/pf/_vti_bin/owssvr.dll" + "?Cmd=Display&List={46A48934-00D5-4914-8EF2-E012AD40343C}" + "&XMLDATA=TRUE&FilterField1=FName&FilterValue1=" + Filter;
// Query the data connection to fill the Months drop-down list box with items con.Execute();