Adding value to a column which is referring to some list for data is not so straight forward. You will need to use SPFieldLookupValueCollectionand, where all the Lookup values will be added along with their source ID. I had use ListBox which contains all the value selected by user which needs to be added to list having MultipleLookupfield.
SPFieldLookupValueCollection lookupValCollection = new SPFieldLookupValueCollection();
SPList listMultiSource = SourceListWhichIsReferred
if (listMultiSource != null)
{
foreach (ListItem listBoxJSelected in listBoxJ.Items)
{
if (listBoxJSelected.Selected == true)
{
foreach (SPListItem listMultiSourceItem in listMultiSource.Items)
{
string strJTitle = Convert.ToString(listMultiSourceItem["Title"]);
if (strJFTitle.Equals(listBoxJSelected.Value))
{
int iD = Convert.ToInt32(listMultiSourceItem["ID"]);
SPFieldLookupValue lookupVal = new SPFieldLookupValue(iD, listBoxJSelected.Value);
lookupValCollection.Add(lookupVal);
}
}
}
}itm["J"] = lookupValCollection;
}
itm.update();
Tuesday, June 2, 2009
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment