获取Infopath中数据源的某列的值

来源:互联网 发布:淘宝靠谱的单反店铺 编辑:程序博客网 时间:2024/06/08 09:11

有一需求,重复表中有一下拉列表,绑定了一个数据源(部门信息,显示部门名称,值为部门ID),现需要根据下拉列表选中的值获得 部门代码。 部门名称,部门ID,部门代码都是数据源中的列。 在下拉列表的 change event 中添加代码

 

public void Dept_Changed(object sender, XmlEventArgs e)        {            // Write your code here to change the main data source.            XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();            XPathNavigator xnText = (XPathNavigator)sender;            XPathNavigator xnName = xnDoc.SelectSingleNode("/my:myFields/my:Dept_Name", this.NamespaceManager);            XPathNavigator xnCode = xnDoc.SelectSingleNode("/my:myFields/my:Dept_Code", this.NamespaceManager);            XPathNavigator xnFD = DataSources["Department Information"].CreateNavigator();            XPathNavigator items = xnFD.SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Department_Information[@ID=" + xnText.Value + "]", NamespaceManager);            xnName.SetValue(items.GetAttribute("Department_Name", ""));            xnCode.SetValue(items.GetAttribute("Department_Code", ""));        }