1

I'm creating a sharepoint survey with VS2012.

I managed to create the survey with several question and here is some sample:

            SPWeb web = properties.GetWeb();
            Guid id = web.Lists.Add("survey", "desc", SPListTemplateType.Survey);
            SPList list = web.Lists[id];

            string Question1 = "choose from option";
            StringCollection collection1 = new StringCollection();
            collection1.Add("opt 1");
            collection1.Add("opt 2");
            collection1.Add("opt 3");
            list.Fields.Add(Question1, SPFieldType.Choice, true, false, collection1);

My question how can I add a question with type Rating Scale ?

I can't find any sample of doing this, maybe need to use (SPFieldRatingScale) but can't understand how.

Hope for any help or directions TIA

1

I managed to do it like that:

string Question3 = "from scale 1 - 5."; StringCollection collection3 = new StringCollection();

            list.Fields.Add(Question3, SPFieldType.GridChoice, true, false, collection3);
            SPFieldRatingScale srs = list.Fields[Question3] as SPFieldRatingScale;
            srs.Choices.Add("some text");
            srs.Choices.Add("another text");
            srs.GridTextRangeLow = "low";
            srs.GridTextRangeHigh = "high";
            srs.GridTextRangeAverage = "avg";
            srs.GridStartNumber = 1;
            srs.GridEndNumber = 5;
            srs.GridNAOptionText = "Not relevant";
            srs.Update();

and than add it to the survey list

0

I never do that but in the MSDN there is a guide How to: Create a Custom Field Value Class that could help you: http://msdn.microsoft.com/en-gb/library/ms480788.aspx

  • I managed to do it like that: – Ronen Apr 9 '13 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.