Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I think about how to add a from lookup value to the text ? How can I write it to another colum ? In the same list.

share|improve this question
    
Yes :), only Value from lookup field. –  Grzegorz Z Nov 28 '12 at 10:03
    
And how get a LookupField in Event Receiver ? –  Grzegorz Z Nov 28 '12 at 11:25
    
but why LookupListName_x003a_ID ? Why why wrait it pernamently ? :) –  Grzegorz Z Nov 28 '12 at 12:40
    
Post it as answer but please first in Your answer tell why we write it pernamently. I don't geret why we write here LookupListName_x003a_ID as pernamently value :) –  Grzegorz Z Nov 28 '12 at 12:53
    
In my example it should be "Procent_x003a_Identyfikator" –  Grzegorz Z Nov 28 '12 at 13:01
add comment

2 Answers 2

up vote 1 down vote accepted

You can extend the ID column into the Child List from Lookup Fields... If you go to Site Settings -> Click lookup Column -> In section "Add a column to show each of these additional fields" check ID field!

Then in code you can access it like:

item["LookupListName_x003a_ID"]

Replace "LookupListName" with the Lookup List's name in your case!

EXPLANATION:
When you extend a column from Lookup field, the name of the field in your list becomes like: LookupListName:FieldName so if you extend ID field, the field name will be LookupListName:ID

Now when you access the fields in code, you need to use Internal Names and all the special characters are replaced by some code... code for ':' is 'x003a', so when you try to access the field in code you will write:
LookupListName_x003a_ID instead of LookupListName:ID

You can see complete code conversions here:
SharePoint Column/Field Display Names vs Internal Names

share|improve this answer
add comment
        SPList list = web.Lists.TryGetList("Your list");
        SPListItem item = list.GetItemByID(ID);
        SPFieldLookupValue fieldLookupValue = new SPFieldLookupValue(item["FieldName"].ToString());
        int lookupID = fieldLookupValue.LookupId;
        string lookupValue = fieldLookupValue.LookupValue;
        item["TextFieldName"] = lookupValue

If I have understood the question correctly...

share|improve this answer
    
And how get the fields in Event Receiver ? –  Grzegorz Z Nov 28 '12 at 11:32
    
public override void ItemUpdated(SPItemEventProperties properties) { base.ItemUpdated(properties); SPListItem item = properties.ListItem; –  Grooverinthesouth Nov 29 '12 at 12:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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