views:

1966

answers:

3

I have a calculated field in a list with this formula: =CID & " - " & Title. When viewing the list, it might display as: "2 - Big Meeting". When I grab the value from code like so: myItem["CIDandTitle"] the value comes back as: "string;#2 - BigMeeting". Is there a "correct" way in sharepoint to extract the value or should i simply split on the semicolon and pound sign?

I am using MOSS2007.

+4  A: 

You have to cast it to an SPCalculatedField:

SPFieldCalculated cf = (SPFieldCalculated)myItem.Fields["CIDandTitle"];
string value = cf.GetFieldValueForEdit(myItem["CIDandTitle"]);

or

string value = cf.GetFieldValueAsText(myItem["CIDandTitle"]);
Nathan DeWitt
That works; as does cf.GetFieldValueAsText(myItem["CIDandTitle"]). This approach seems clunky though.
Chloraphil
less clunky than splitting on the semicolon and hash...
Nathan DeWitt
I had issues trying to get a float this way. I used myItem.GetFormattedValue("floatValue");
bryanbcook
A: 

I have a similar field of type note in which values are stored ';#' seperated. As I am storing the multiple values in databse seperated by ';#'.

In edit mode i display these values in listbox which will support multiple selection.

Only issue is in view properties mode the values are shown as ';#' seperated and my reqmt is to show them as ',' seperated.

I have the function GetValueasText in my custom field - but no effect..

Any input on this will be appreciated.

Thanks, Poonam

Poonam
Poonam, you should ask a new question with your problem.
Chloraphil
A: 

Very good usefull post! Thanks!!!

Vincius Ferreira da Rosa
this doesn't answer the question. If you want to add this as a comment to the original question, then that would be appropriate.
Nathan DeWitt