Hi,
I have a SharePoint list with fields: "DisplayName","Value","Type". the list should populate several drop downs in an Info path 2007 browser-compatible form.
- The type determines to which drop down the data should be populated to.
- I Can't filter the data from the list on the design because it's a browser compatible form.
- The request was not to separate the data into several lists.
- I have tried to use code behind with some success, but it seems too much to do for such a small request(code is below)
is there a Proper\Normal way to do it?
private string GetFieldName(XPathNavigator DS)
{
string displayName = DS.SelectSingleNode("@Name",
NamespaceManager).Value;
return displayName;
}
private string
GetFieldValue(XPathNavigator DS)
{
string value = DS.SelectSingleNode("@Value", NamespaceManager).Value;
return value;
}
public void
InternalStartup()
{
FillDropDown("Type1");
}
private void
FillDropDown(string DropDownName)
{
XPathNodeIterator ProjectSites =
DataSources["OptionList"].CreateNavigator().Select(String.Format("/dfs:myFields/dfs:dataFields/dfs:OptionList[@Type='{0}']",
DropDownName), NamespaceManager);
RemoveFirstItem(DropDownName);
foreach (XPathNavigator ProjectSite in
ProjectSites)
{
string Val = GetFieldValue(ProjectSite);
string DisplayName = GetFieldName(ProjectSite);
AddItem(DropDownName,Val, DisplayName);
}
}
private void
RemoveFirstItem(string DropDownName)
{
XPathNavigator DOM = MainDataSource.CreateNavigator();
XPathNavigator group1 =
DOM.SelectSingleNode(String.Format("/my:myFields/my:{0}",
DropDownName), NamespaceManager);
group1.MoveToFirstChild();
group1.DeleteSelf();
}
private void
AddItem(string DropDownName,string itemId, string itemName)
{
XPathNavigator DOM =
this.MainDataSource.CreateNavigator().SelectSingleNode(String.Format("/my:myFields/my:{0}",
DropDownName), NamespaceManager);
XPathNavigator XClone = DOM.Clone();
XClone.SelectSingleNode(String.Format("/my:myFields/my:{0}/my:DisplayName",DropDownName),
NamespaceManager).SetValue(itemName);
XClone.SelectSingleNode(String.Format("/my:myFields/my:{0}/my:Value",
DropDownName), NamespaceManager).SetValue(itemId);
DOM.InsertAfter(XClone);
}