Binding Dropdown in infopath form load without using Data Connections ( Dropdown [Get choices from fields in this form]) using code behind.
- Go to Infopath form, Add one Group (like test),set properties -check (Repeating).
- Add two fields (like test_displayname and test_value) under Group.
- Add one Dropdown,set properties (Get choices from fields in this form).
- set the value as Group [like test_displayname and test_value].
- go to on form load events write the code.
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
XPathNavigator myRootNode = MainDataSource.CreateNavigator();
XPathNavigator userNode = myRootNode.SelectSingleNode("/my:myFields/my:test", NamespaceManager);
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPList userlist = web.Lists["Departments"];
SPListItemCollection usercollection = userlist.GetItems();
{
XPathNavigator myRootNode = MainDataSource.CreateNavigator();
XPathNavigator userNode = myRootNode.SelectSingleNode("/my:myFields/my:test", NamespaceManager);
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPList userlist = web.Lists["Departments"];
SPListItemCollection usercollection = userlist.GetItems();
if (usercollection.Count > 0)
{
foreach (SPListItem item in usercollection)
{
XPathNavigator newNode = null;
newNode = userNode.Clone();
newNode.SelectSingleNode("/my:myFields/my:test/my:test_displayname", this.NamespaceManager).SetValue(item.Title);
newNode.SelectSingleNode("/my:myFields/my:test/my:test_value", this.NamespaceManager).SetValue(item.Title);
userNode.InsertAfter(newNode);
newNode = null;
}
userNode.DeleteSelf();
userNode = null;
}
}
}
{
foreach (SPListItem item in usercollection)
{
XPathNavigator newNode = null;
newNode = userNode.Clone();
newNode.SelectSingleNode("/my:myFields/my:test/my:test_displayname", this.NamespaceManager).SetValue(item.Title);
newNode.SelectSingleNode("/my:myFields/my:test/my:test_value", this.NamespaceManager).SetValue(item.Title);
userNode.InsertAfter(newNode);
newNode = null;
}
userNode.DeleteSelf();
userNode = null;
}
}
}
No comments:
Post a Comment