Tuesday 20 January 2015

Rating Scale in SharePoint Survey List Programmatically

In SharePoint Survey List, Rating scale is very easy to implement, set properties and use this in SharePoint. I found an easy way to implement this rating scale in SharePoint using coding in Feature activation.

When you are Creating a survey list programmatically, add this field to the SharePoint survey list.


Code:
//Adding Question to Survey List Programmatically with rating scale
strQuestionTitle = "Lecturer Skills";
StringCollection strQuestions = new StringCollection();
strQuestions.Add("Approachability");
strQuestions.Add("Availability");
strQuestions.Add("Share Knowledge");
strQuestions.Add("Motivate");
strQuestions.Add("Provide guidance");
objSurvey.Fields.Add(strQuestionTitle, SPFieldType.GridChoice, true, false, strQuestions);
//Updating Rating scale field properties
SPFieldRatingScale srs = objSurvey.Fields[strQuestionTitle] as SPFieldRatingScale;
srs.GridTextRangeLow = "Low";
srs.GridTextRangeHigh = "High";
srs.GridTextRangeAverage = "Avg";
srs.GridStartNumber = 1;
srs.GridEndNumber = 5;
srs.GridNAOptionText = "NA";
srs.Update();
//Updating survey list
objSurvey.Update();
 Hope this article is helpful and here ends your searching.

No comments:

Post a Comment