Home > Sharepoint > Optional SPFieldLookupValue column in list and (none) yields different results!

Optional SPFieldLookupValue column in list and (none) yields different results!

February 5th, 2009

Suppose you have a list with a lookup field to another list, that is optional. Selecting “(none)” in the lookup yields different values in the column, depending on the layout of the lookup.

Lookup fields have different displays depending on the number of items in the list. It’s either a regular dropdown list (
<select>) or a select with 8 visible rows that pops up after you click the arrow-down icon.

Normal view:

 

Normal select-box, less than 20 items

Normal select-box, less than 20 items

 

 

Other view:

 

Irregular select-box, more than 20 items

Irregular select-box, more than 20 items

 

 

The first alternative gives the field value

null

and the second alternative gives the field value

"0;#"

The normal view is for lookups with less than 20 values.

I have not found anything about this behaviour in the documentation.

LookupField control

The control rendering the output for a lookup is the LookupField. Using reflector I found the reason in code (but not in the docs):

In CreateChildControls there is an if-statement checking if there are more than 20 items in the list, rendering the “Other view”.

Look at the DataSource property:

if (!lookup.Required && !lookup.AllowMultipleValues)
{
    DataRow row = table.NewRow();
    row[0] = 0;
    row[1] = SPResource.GetString("LookupFieldNoneOption", new object[0]);
    table.Rows.Add(row);
    num++;
}

peter Sharepoint

  1. No comments yet.
  1. No trackbacks yet.