Public member 'Value' on type 'FieldDefinitionKeyPair' not found

×

Error: Public member 'Value' on type 'FieldDefinitionKeyPair' not found

Description:  This error occurs when attempting to use the Value of a Custom field with the following syntax:

DataList:
<%# Container.DataItem.Fields("MyFieldName").Value %>
Item:
Item.Fields("MyFieldName").Value

Technically speaking, Fields("MyFieldName") hands back a FieldDefinitionKeyPair object, not a Field object.

Resolution:  FieldDefinitionKeyPair implements the IField Interface, so the following syntax will work:

DataList:
<%# CType(Container.DataItem.Fields("MyFieldName"),IField).Value %>
Item:
CType(Item.Fields("MyFieldName"),IField).Value