[英]GridView Asp .Net-Changing the selected value of a second drop down list based on value of first drop Down in same column
[英]Updating a field on list items based on the value selected from drop down “choice” column
我有以下問題,我有兩個列表“ TestUsers”和“ TestGroups”。 “ TestUsers”列表具有兩列:[組-選擇],[用戶-單行文本]。 “ TestGroups”列表具有兩列[Group-單行文本],[CheckedOut-單行文本]。
這兩個列表中的數據如下:
TestUsers(列表):用戶:testuser1組:groupA
用戶:testuser2組:groupB
TestGroups(列表):組:groupA CheckedOut:testuser1
要求是,當“ TestUsers”列表中的用戶將其“組”從“ groupA”更改為“ groupB”時,也應在“ TestGroups”列表中將其反映並自動更新。 因此,例如,在“ TestUsers”列表中,如果我要將“ testuser1”的“組”更改為“ groupB”,則在“ TestGroups”列表中,“ testuser1”的“組”也必須更改/更新為“ groupB” ”。
我希望以上內容足以清楚地說明要求是什么。
我嘗試使用worklflows進行此操作,並具有查找列和計算列。 但是,計算列和查找列似乎都不起作用。
我將如何使用c#中的代碼來實現這一目標。 我知道如何更新列表項,但是我不確定如何在如前所述的單獨列表中更改值時如何從列表中更新列表項。
我對此問題感到困惑,並認為我將其發布在這里,以便可以快速,准確地獲得有關如何進行操作的建議。
非常感謝,對此的任何幫助將不勝感激。
您可以嘗試在事件接收器中使用ItemUpdating
Event方法,只需檢查是否已更改項目並創建邏輯
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.
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.