英文原文:http://www.sharepoint-tips.com/2007/01/infopath-form-services-implementing.html
1.
在用数据库或者JS中我们也许做过类似城市级联功能! 这里使用infoPath表单 ,从sharepoint列表中获取数据!
首先新建2个自定义列表: province 和 cities
在cities列表中 创建一列名为 :province 相
cities添加数据的时候,province的数据就会读取 province 列表里 title字段的值!
目前2张列表数据准备就绪!
2.
如果你不设置安全和信任为 完全信任,也许你将得到这个错误:
现在点击 预览 按钮,可以看到,2个dropdwonlist都有值, 但是 city不会随上面的 province 变化! 接下来需要 编辑province Changed事件 !
如下图:打开VSTA开发环境,写自己熟悉的C#代码!
把下面的代码Copy到你的工程中
public void province_Changed(object sender, XmlEventArgs e) { SetCitiesOptions(e); } private void SetCitiesOptions(XmlEventArgs e) { //cities 为刚才第10布,键入数据链接名称:?cities FileQueryConnection q = (FileQueryConnection)this.DataConnections["cities"]; MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:city", NamespaceManager).SetValue(""); //这?里?的?FilterField1=province , province为?上?面?ows_province去?掉?ows_的?剩?下?部?分?, 其?实?也?是?你?在?cities列?表?中?province项?, q.FileLocation = q.FileLocation + "&FilterField1=province&FilterValue1=" + e.NewValue; //断?点?调?试?q.FileLocation = http://moss/_vti_bin/owssvr.dll?Cmd=Display&List={CD8B96B9-F9FE-4055-9E0B-9EC56B46A4F5}&XMLDATA=TRUE&FilterField1=province&FilterValue1=四?川?省? //可?把?该?地?址?复?制?到?浏?览?器?,即?可?看?到?查?询?的?结?果? q.Execute(); }
我遇到的问题:
1.System.Collections.Generic.KeyNotFoundException The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Microsoft.Office.InfoPath.Internal.DataConnectionsHost.get_Item(String name) at province.FormCode.SetCitiesOptions(XmlEventArgs e) in D:\Users\Documents\InfoPath Projects\province\FormCode.cs:line 40 at province.FormCode.province_Changed(Object sender, XmlEventArgs e) in D:\Users\Documents\InfoPath Projects\province\FormCode.cs:line 35 at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type) at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent) at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent)问题原因:FileQueryConnection q = (FileQueryConnection)this.DataConnections["cities"]; 这里的cities填写错误, 输入了其他数据名,或者大小写没有注意
2. 如果你选择第一个下拉列表,第二个为空,而且没有抛出任何错误,你可以断点这里q.FileLocation = q.FileLocation+ "&FilterField1=province&FilterValue1=" + e.NewValue; 把得到的链接在浏览器打开,看是否也为空,如果同样为空,则
FilterField1=province的province字段你写错了或者数据本来就为空(如:列表中四川下面你没有填写任何城市)!3.System.Net.WebException InfoPath has encountered an error. The operation failed. The form's code contains an error. The following call in the form's code failed: XMLFileAdapter.Query Operation aborted at Microsoft.Office.InfoPath.Internal.MomExceptionHelper.ExecuteDataConnectionAction(OMCall d) at Microsoft.Office.InfoPath.Internal.FileQueryConnectionHost.Execute() at province.FormCode.SetCitiesOptions(XmlEventArgs e) in D:\Users\Documents\InfoPath Projects\province\FormCode.cs:line 55 at province.FormCode.province_Changed(Object sender, XmlEventArgs e) in D:\Users\Documents\InfoPath Projects\province\FormCode.cs:line 35 at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type) at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent) at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent)
问题原因:在操作第8不的时候,错误的将XML文件保存下来,而且下面错误的浏览了本地文件,而是应该键入:http://moss/_vti_bin/owssvr.dll?Cmd=Display&List={CD8B96B9-F9FE-4055-9E0B-9EC56B46A4F5}&XMLDATA=TRUE 即可!![]()
其他相关文字:http://www.cnblogs.com/sean_zhang/archive/2009/07/27/1532009.html