locked
Retrieving a Boolean value from a list RRS feed

  • Question

  • Guys,

    I need to retrieve a list item that is boolean in nature. How would i do it? I am trying the following code:

            foreach (SPListItem item in itemColl)
            {
                foreach(SPField itemField in item.Fields)
                {
                    if(itemField.Type == SPFieldType.Boolean)
                    {
                        //How do i retrieve the stored value??
                    }
        
                }
            }
    Tuesday, February 10, 2009 6:50 PM

Answers

  • Hi

    How about:
     

                        foreach (SPListItem item in List.Items)
                        {
                            foreach (SPField field in item.Fields)
                            {
                                if (field is SPFieldBoolean)
                                {
                                    try
                                    {
                                        if (field.InternalName == "Boolean")
                                        {
                                            Boolean MyValue = (Boolean)item[field.Id];
                                         }
                                       
                                    }
                                    catch
                                    {
                                    }
                                }

                            }

    Note: You should check against your field internalname or title, if you retrieve all fields of SPFieldBoolean. You probably will get an exception on the internal field _HasCopyDestinations

    Regards
    CB-)

    Tuesday, February 10, 2009 9:18 PM