I want to set the multiple values in lookup column. my string format is id#;id#;id#; but it is giving error.
-
What error do you get? And also can you please post the code you used. This will make easy for providing solution.– Asad RefaiCommented Feb 26, 2016 at 10:53
-
Read sharepoint.stackexchange.com/questions/29491/…– Asad RefaiCommented Feb 26, 2016 at 10:57
-
Ya I got List<FieldLookupValue> branchLookupValueList = new List<FieldLookupValue>(); string[] branchIds = userInformation.Branch_Name.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); foreach (var branchId in branchIds) { FieldLookupValue LookupColBranch = new FieldLookupValue(); LookupColBranch.LookupId = Convert.ToInt32(branchId); branchLookupValueList.Add(LookupColBranch); } NewItem["BranchName"] = branchLookupValueList;– sachinCommented Feb 26, 2016 at 11:37
Add a comment
|
2 Answers
Try this below code:
String [] idsCol = id.split("#;"); //id = your string "id#;id#;id#;"
SPFieldLookupValueCollection fieldValues = new SPFieldLookupValueCollection();
foreach(string s in idsCol)
{
fieldValues.Add(new SPFieldLookupValue{LookupId=(Convert.ToInt32(s))});
}
SPListItem newItem = list.Items.Add(); //list = your desired list object
newItem["Your column name"] = fieldValues;
newItem.Update();
List<FieldLookupValue> branchLookupValueList = new List<FieldLookupValue>();
string[] branchIds = userInformation.Branch_Name.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
foreach (var branchId in branchIds)
{
FieldLookupValue LookupColBranch = new FieldLookupValue();
LookupColBranch.LookupId = Convert.ToInt32(branchId);
branchLookupValueList.Add(LookupColBranch);
}
NewItem["BranchName"] = branchLookupValueList;