1

I want to set the multiple values in lookup column. my string format is id#;id#;id#; but it is giving error.

3
  • What error do you get? And also can you please post the code you used. This will make easy for providing solution.
    – Asad Refai
    Commented Feb 26, 2016 at 10:53
  • Read sharepoint.stackexchange.com/questions/29491/…
    – Asad Refai
    Commented 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;
    – sachin
    Commented Feb 26, 2016 at 11:37

2 Answers 2

2

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();
1
  • Please do upvote answer, if it is helpful to you:) Commented Feb 26, 2016 at 15:07
2
 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;

Not the answer you're looking for? Browse other questions tagged or ask your own question.