Adding a single value and multiple values into a Lookup Column

There might be situations where you may have to add multiple values to a SharePoint list field.


SPFieldMultiChoiceValue multiChoiceFunction = new SPFieldMultiChoiceValue();

for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
int lvId = Convert.ToInt32(CheckBoxList1.Items[i].Value);
string lvValue = CheckBoxList1.Items[i].Text.ToString().Trim();
SPFieldLookupValue lv = new SPFieldLookupValue(lvId, lvValue);
multiChoiceFunction.Add(lv.ToString());
}
}

item["Function"] = multiChoiceFunction;

below is the code snippet of the way to add a value to a SharePoint look up column field :

foreach (ListItem lst in RadioButtonList1.Items)
{
if (lst.Selected == true)
{
int lvId = Convert.ToInt32(lst.Value);
string lvValue = lst.Text.ToString().Trim();
SPFieldLookupValue lv = new SPFieldLookupValue(lvId, lvValue);
item["TypeOfTest"] = lv;
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: