Rating Scale in SharePoint Survey List using C#.Net Code

In SharePoint Survey List, Rating scale is very useful and easy to implement, set properties and use in SharePoint. It is a column type which is available only for the survey lists. If we are creating Survey lists using C#.Net code snippet, I found an easy way to implement this rating scale in SharePoint using Feature activation coding.

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.
Rating Scale in SharePoint Survey List using C#.Net Code Rating Scale in SharePoint Survey List using C#.Net Code Reviewed by Sudheer Gangumolu on November 26, 2014 Rating: 5

No comments: