Infopath 2010 form drop-down list change event get data programmatically
A short code snippet to get the data from a datasource on change event of a drop-down list in Infopath 2010 form.
In the code below the method InternalStartup() is called to register the event change for the dropdown and the method mydropdown_Changed() is called to access the actual datasource “MyDATASOURCE” for retrieving the values for Field1 or sharepoint Title column from the sharepoint list datasource(MyDATASOURCE).
The parameter passed to the Datasource via the webservice is ID of the drop-down item.
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System;
using System.Xml;
using System.Xml.XPath;
namespace Getdatanamespace
{
public partial class FormCode
{
public void InternalStartup()
{
EventManager.XmlEvents["/my:myform/my:table1/my:mydropdown"].Changed += new XmlChangedEventHandler(mydropdown_Changed);
}
{
public partial class FormCode
{
public void InternalStartup()
{
EventManager.XmlEvents["/my:myform/my:table1/my:mydropdown"].Changed += new XmlChangedEventHandler(mydropdown_Changed);
}
public void mydropdown_Changed(object sender, XmlEventArgs e)
{
{
XPathNavigator form = MainDataSource.CreateNavigator();
// Set parameter for web service request and query connection
DataSources["MyDATASOURCE"].CreateNavigator().SelectSingleNode(“/dfs:myFields/dfs:queryFields/q:SharePointListItem_RW/q:ID”,NamespaceManager).SetValue(e.NewValue); ->> sending the ID as a parameter to the webservice call which will access the datasource
DataSources["MyDATASOURCE"].CreateNavigator().SelectSingleNode(“/dfs:myFields/dfs:queryFields/q:SharePointListItem_RW/q:ID”,NamespaceManager).SetValue(e.NewValue); ->> sending the ID as a parameter to the webservice call which will access the datasource
DataSources["MyDATASOURCE"].QueryConnection.Execute();
// Create navigator on web service response
XPathNavigator resultnav = DataSources["MyDATASOURCE"].CreateNavigator();
XPathNavigator resultnav = DataSources["MyDATASOURCE"].CreateNavigator();
// Set fields with values from web service response
XPathNavigator Field1 = form.SelectSingleNode(“/my:myform/my:table1/my:field1″, NamespaceManager);
Field1.SetValue(resultnav.SelectSingleNode(“/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title”,NamespaceManager).Value);
}
XPathNavigator Field1 = form.SelectSingleNode(“/my:myform/my:table1/my:field1″, NamespaceManager);
Field1.SetValue(resultnav.SelectSingleNode(“/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title”,NamespaceManager).Value);
}
}
}
}
No comments:
Post a Comment