views:

305

answers:

1

Hello,

I was trying to create a custom field type similar to lookup column just mine is filtered lookup column.Its working fine but I wanted to implement the same functionality like lookup column does,by that I mean:

For e.g lookup column is having title of some list so it stores its value as

SPListiem.ID#;title....but it shows only title when we r selecting or editing value in it.

I am using listboxes and doing

listbox.Items.Add(title);

but how to get Id also and specially hidden from users like lookup column does....means I can do like this... listbox.Items.Add(title+"#;" + SPListitem.ID)...

but I dont want this....

Any idea how to achieve this...

+1  A: 

Your solution

Indeed, it stores value as LookupId;#LookupValue

  1. Use SPFieldLookupValue (or SPFIeldLookupValueCollection for multiple lookups) constructor and then you get SPFieldLookupValue.LookupId and SPFieldLookupValue.LookupValue properties.
  2. Then, to add items to ListBox with ID, use

    listbox.Items.Add(new ListItem(lookupValue.LookupValue, lookupValue.LookupId));
    

    then user will see LookupValue, but you will have a way to get coresponding ID.

Already existing solution

By the way, there is already available SharePoint filtered lookup field which you may use if you wish.

Janis Veinbergs

related questions