views:

561

answers:

2

I have write a custom field that extends SPFieldLookup. I set AllowMultipleValues = true; Here is Field Control Value:

public override object Value
    {
        get
        {
            EnsureChildControls();
            SPFieldLookupValueCollection vals = new SPFieldLookupValueCollection();
            ICollection s = TinBaiLienQuanPicker.SelectedIds;
            if (s != null && s.Count > 0)
            {
                foreach (var i in s)
                {
                    ListItem z = availableItems.Find(x => (x.Value == i.ToString()));
                    if (z != null)
                    {
                        vals.Add(new SPFieldLookupValue(int.Parse(z.Value), z.Text));
                    }
                }
            }
            return vals;
        }
        set
        {
            EnsureChildControls();
            base.Value = value as SPFieldLookupValueCollection;
        }
    }

When control save field data, I see it return a collection which have multiple value. But when I retrieve data again, I receive only the first value. I get value from Control Field ' ListItemFieldValue property.

Please give me a tip. Thank you very much.

A: 

Data storage logic is different in the database for lookup field with one value compared to multiple values. Check that in the field type definition xml ParentType is set to LookupMulti instead of Lookup.

EG
Hi,EG. Thank for your reply. ParentType was already set to LookupMulti .
Dau Thanh Hai
A: 

You have to inherit the field control class from MultipleLookupField not from LookupField. Are you sure you are doing this?

naivists
Hi, naivists.When I extend BaseFieldControl, I get only one value in both Display and Edit mode. When I change inheritance to LookupField or MultipleLookupField as you say, the field returns correct value in edit mode only. In display mode, only first Item is returned.Thanks.
Dau Thanh Hai
"december cumulative update" of SharePoint actually talks about your, too: "You develop a custom field type that inherits from the SPFieldLookUp class. You want to store multiple values in a field of that custom field type. Therefore, you set the AllowMultipleValues property to True. However, after you set the AllowMultipleValues property to True, the field type is displayed as Lookup instead of the custom field type." http://support.microsoft.com/kb/977022/
naivists