TODO:
Have you ever had a lookup column, and you want to get its value programatically using C#?
1. I have a column that is called, Task Id.
2. "Task Id" in #1, is a lookup to the "ID" column of a list called "Tasks"
3. I have an event receiver that needs to get the "Task Id" from the form.
SOLUTION:
//my event receiver code....
public override void ItemAdded(SPItemEventProperties properties)
{
SPFieldLookup lookupField = properties.ListItem.Fields["Task ID"] as SPFieldLookup;
SPFieldLookupValue taskIdVal = null;
object obj = properties.ListItem["Task ID"];
if (lookupField != null)
taskIdVal = lookupField.GetFieldValue(obj.ToString()) as SPFieldLookupValue;
string taskId = taskIdVal.LookupValue;
}
NOTES:
There are no notes on this topic.