1

I am trying to get value of item field from the list. The field is a lookup field with integer value. When I am trying get the value it is coming like 9;#9 (shown below). But I need only 9.

enter image description here

web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Project/Task Status Details"];
SPListItem item = properties.List.GetItemByIdSelectedFields(properties.ListItem.ID, "Project_x002f_Task_x0020_Status_");
int details = (int)item["Project_x002f_Task_x0020_Status_"];//Error here

How get only value of it? not with hash.

3

By default, a lookup field contains just one value. In this case, the field value is an object of type String, and the string has the following format: Id;#Value

Use int value = new SPFieldLookupValue(item["Project_x002f_Task_x0020_Status_"] as String).LookupValue to read the lookup value and int id = new SPFieldLookupValue(item["Project_x002f_Task_x0020_Status_"] as String).LookupId to read the Id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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