简体   繁体   English

在此上下文中不存在名称“ e”。

[英]The name “e” does not exist in this context.

I've been looking at other posts to try to fix the problem but I am really new to coding in InfoPath. 我一直在寻找其他文章以尝试解决此问题,但是我真的是InfoPath编码的新手。 I have a code that is supposed to allow me to use Infopath to udpate items in a SharePoint list. 我有一个应该允许我使用Infopath udpate SharePoint列表中的项目的代码。 I keep getting the error that "the name "e" does not exist in the current context". 我不断收到这样的错误消息:“名称“ e”在当前上下文中不存在”。 Please help!! 请帮忙!!

    public void InternalStartup()
    {
        ((ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked += new ClickedEventHandler(UpdateList_Clicked("Update", e.Source.CreateNavigator()));
    }
    public void UpdateList_Clicked(string strOperation, XPathNavigator e)
    {
        //Create a new instance of our "Lists" web service
        ServerName.Lists myList = new ServerName.Lists();
        //Pass the logged on users credentials to the web service
        myList.Credentials = System.Net.CredentialCache.DefaultCredentials;
        //Create a DataSource object for our list data source
        DataSource dsContacts = this.DataSources["Updated Headcount"];
        //Create a NamespaceManager object so we can use the various namespaces on our XPATH expressions
        XmlNamespaceManager ns = this.NamespaceManager;
        //Create XPathNavigator objects for each field from our list
        XPathNavigator xnID = e.SelectSingleNode("@ID", ns);
        XPathNavigator xnTitle = e.SelectSingleNode("@Title", ns);
        XPathNavigator xnLastName = e.SelectSingleNode("@LastName ", ns);
        XPathNavigator xnFirstName = e.SelectSingleNode("@FirstName", ns);
        XPathNavigator xnFranchise = e.SelectSingleNode("@Franchise", ns);
        XPathNavigator xnLocation = e.SelectSingleNode("@Location", ns);
        XPathNavigator xnPillar = e.SelectSingleNode("@Pillar", ns);
        XPathNavigator xnLeader = e.SelectSingleNode("@Leader", ns);
        XPathNavigator xnActivity = e.SelectSingleNode("@Activity", ns);
        XPathNavigator xnCategory = e.SelectSingleNode("@Category", ns);
        XPathNavigator xnPosition = e.SelectSingleNode("@Position", ns);
        XPathNavigator xnDeptNumber = e.SelectSingleNode("@DeptNumber", ns);
        XPathNavigator xnSupervisor = e.SelectSingleNode("@Supervisor", ns);
        XPathNavigator xnEmployeeType = e.SelectSingleNode("@EmployeeType", ns);
        XPathNavigator xnFTE = e.SelectSingleNode("@FTE", ns);
        XPathNavigator xnNotes = e.SelectSingleNode("@Notes", ns);
        //Create a new XmlDocument to use for specifying the Update CAML query
        XmlDocument doc = new XmlDocument();
        //Create the needed update element
        System.Xml.XmlElement updates = doc.CreateElement("Batch");
        //Create the CAML query passing in the value of each of our fields from the form
        if (strOperation == "Delete")
        {
            updates.InnerXml = string.Format(@"<Method ID='1' Cmd='Delete'>" +
            "<Field Name='ID'>" + xnID.Value + "</Field>" + "</Method>");
        }
        else
        {
            //Create the CAML query passing in the value of each of our fields from the form
            updates.InnerXml = string.Format(@"<Method ID='1' Cmd='Update'>" +
            "<Field Name='ID'>" + xnID.Value + "</Field>" +
            "<Field Name='Title'>" + xnTitle.Value + "</Field>" +
            "<Field Name='LastName'>" + xnLastName.Value + "</Field>" +
            "<Field Name='FirstName'>" + xnFirstName.Value + "</Field>" +
            "<Field Name='Franchise'>" + xnFranchise.Value + "</Field>" +
            "<Field Name='Location'>" + xnLocation.Value + "</Field>" +
            "<Field Name='Pillar'>" + xnPillar.Value + "</Field>" +
            "<Field Name='Leader'>" + xnLeader.Value + "</Field>" +
            "<Field Name='Activity>" + xnActivity.Value + "</Field>" +
            "<Field Name='Category'>" + xnCategory.Value + "</Field>" +
            "<Field Name='Position>" + xnPosition.Value + "</Field>" +
            "<Field Name='DeptNumber'>" + xnDeptNumber.Value + "</Field>" +
            "<Field Name='Supervisor'>" + xnSupervisor.Value + "</Field>" +
            "<Field Name='EmployeeType'>" + xnEmployeeType.Value + "</Field>" +
            "<Field Name='FTE'>" + xnFTE.Value + "</Field>" +
            "<Field Name='Notes'>" + xnNotes.Value + "</Field>" + "</Method>");
        }
        //Update the list
        XPathNavigator xnListGUID = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ListName", ns);
        XmlNode node = myList.UpdateListItems(xnListGUID.Value, updates);
        //Requery the data source to reflect the updates
        dsContacts.QueryConnection.Execute();      
    }

}

} }

Assuming Clicked is an event with void (string, XPathNavigator) signature, you should add event handler this way: 假设Clicked是一个具有void (string, XPathNavigator)签名的事件,则您应该通过以下方式添加事件处理程序:

public void InternalStartup()
{
    ((ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked += UpdateList_Clicked;
}

Did you mean 你的意思是

public void InternalStartup()
{
    ((ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked +=
      (s, e) => UpdateList_Clicked("Update", e.Source.CreateNavigator());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 名称“…”在当前上下文中不存在。 错误 - The name “…” does not exist in the current context. error “当前上下文中不存在名称‘DisplayAlert’。” Xamarin C# - “The name ”DisplayAlert“ does not exist in current context.” Xamarin C# 当前上下文中不存在名称 userInput。 为什么? - The name userInput does not exist in the current context. Why? 该名称在当前上下文中不存在。 不上课 - The name does not exist in the current context. Not seeing class 在当前上下文中不存在。 变量声明 - Does not exist in the current context. Variable declaration 当前上下文中不存在名称“ABC...”。 c#SQL控制台程序 - The name "ABC..." does not exist in the current context. c# SQL Console program C#error1:当前上下文中不存在名称“DateTimeStyles”。 error2:找不到类型或命名空间名称“CultureInfo” - C# error1:The name 'DateTimeStyles' does not exist in the current context. error2:The type or namespace name 'CultureInfo' could not be found 上下文中不存在 MVC 项。 怎么了? - MVC item does not exist in the context. What is wrong? Xamarin Forms“...DisplayAlert 在当前上下文中不存在。” - Xamarin Forms “…DisplayAlert does not exist in the current context.” 当前上下文中不存在“会话”。 我该如何使用它? - 'Session' does not exist in the current context. How can I use it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM