locked
Get the value from SPFiledChoice RRS feed

  • Question

  • Hi All

     

    I have a page in which one field(added to the content type of which the page is based on) is a SPFieldChoice.

    It has two options YES and NO. The default is YES.

     

    When a page is created the owner selects a choice. I need to read the selected value through code.

    I am able to see the DefaultValue and the list of Choices. But could not figure out how to get the selected value ??

     

     

    Please Help, Thanks in Advance

    Saturday, June 28, 2008 12:36 PM

Answers

All replies

  • You can get the value from the SPListItem[fieldName]. However, some of the types can be a little tricky sometimes - such as lookups, urls, and even choices. If you don't want to figure out the strings the SPListItem returns, you can cast them to their native types using the SPField object.

    Here is a blog on how to do it: http://blog.gemsolution.co.uk/2008/04/24/retrieving-values-from-spfield-objects-not-itemtostring/

     

    Saturday, June 28, 2008 1:23 PM
  • Thanks Greg

     

    SPFieldChoice chVisiblity = (SPFieldChoice)currentSitePage.File.Item.Fields["MyChoiceField"];

    string value = chVisiblity.GetFieldValueAsText(currentSitePage["MyChoiceField"]);

     

    Monday, June 30, 2008 4:49 AM
  • Hi,

    I have tried the above code i am not able to get the select value, i am getting the default value , is there any other code

    Wednesday, October 26, 2011 11:32 AM