1

我有以下问题我有两个列表“TestUsers”和“TestGroups”。“TestUsers”列表有两列 [Group - Choice]、[User - Single line of text]。“TestGroups”列表有两列 [Group - Single line of text]、[CheckedOut - Single line of text]。

两个列表中的数据如下:

TestUsers(列表):用户:testuser1 组:groupA

用户:testuser2 组:groupB

测试组(列表):组:groupA 签出:testuser1

要求是,当“TestUsers”列表中的用户将其“Group”更改为例如从“groupA”更改为“groupB”时,这也应该在“TestGroups”列表中反映并自动更新。因此,例如在“TestUsers”列表中,如果我要将“testuser1”的“Group”更改为“groupB”,那么在“TestGroups”列表中,“testuser1”的“Group”也必须更改/更新为“groupB” ”。

我希望以上内容足以清楚地描述要求是什么。

我已经尝试使用工作流和查找列以及计算列来执行此操作。但是计算列和查找列似乎都不起作用。

我将如何使用 c# 中的代码来实现这一点。我知道如何更新列表项,但我不确定当前面提到的单独列表上的值发生更改时如何更新列表中的列表项。

我被这个问题困住了,想把它贴在这里,这样我就可以得到一些关于如何进行的快速准确的建议。

非常感谢,对此的任何帮助将不胜感激。

4

1 回答 1

1

你可以试试这个在事件接收器中使用ItemUpdating事件方法只是检查它是否改变了项目并创建你的逻辑

 public override void ItemUpdating(SPItemEventProperties properties)
    {
        base.ItemUpdated(properties);
        if (properties.ListTitle == "TestUsers")
        {
            SPWeb web = properties.OpenWeb();
            SPList list = web.Lists[properties.ListTitle];
            SPListItem litemUser = list.GetItemById(properties.ListItemId);


            SPList objFeatureList = web.Lists["TestGroups"];
            SPQuery objParentQuery = new SPQuery();

            string user = properties.AfterProperties["User"].ToString();

            //in Caml query just find it out listitem which contain Users and than update its listitem.
            objParentQuery.Query = "<Where><Eq><FieldRef Name='Check_x0020_it_x0020_out'/><Value Type='Integer'>"+You should set Userid in Field From litemUser +"</Value></Eq></Where>";
            SPListItemCollection liitemcol = objFeatureList.GetItems(objParentQuery);
            foreach (SPListItem litemGroup in liitemcol)
            {
                litemGroup["Group"] = litemUser["Group"];
                litemGroup.Update();

                // or if you want to using Workflow just startWorflow when item has match over here.
            }

        }
    }
于 2012-03-19T12:49:06.610 回答