Survey Rating type question submit programmatically RRS feed

  • Question

  • Hi,

    I have created a single survey question of type Rating which have 10 sub-questions regarding rating with 4 Number Range.

    I am using custom aspx page to render its Survey Sub-Questions.I am using repeater control to render that sub-question list in which i am using a RadioButtonList as well.

    Now what code should i write to submit  that response.

    My logic to render the sub-question is like this :


    public void GetSurveyQuestions(string siteUrl, string surveyName)
                using (SPSite oSPSite = new SPSite(SPContext.Current.Site.Url))
                    using (SPWeb oSPWeb = oSPSite.OpenWeb())
                        SPList surveyList = oSPWeb.Lists.TryGetList(surveyName);

                        foreach (SPField field in surveyList.Fields)
                            if (field.Type == SPFieldType.GridChoice)
                                SPFieldRatingScale choiceField =(SPFieldRatingScale)field;
                                DataRow dr;
                                foreach (string choiceName in choiceField.Choices)
                                    if (!string.IsNullOrEmpty(choiceName))
                                        dr = table.NewRow();
                                        dr[QuestionColumn] = choiceName;
                RepDetails.DataSource = table;

    Thanks & Regards,



    • Edited by Airwings Friday, October 25, 2013 8:47 AM Typo
    Friday, October 25, 2013 8:45 AM


  • Got answer myself....

    Sharepoint stores that column as a simple text and separates the answer by #; 

    For Eg.

    Lets say you have 10 questions and 4 Number Rating as shown below

    Q1     (o o o o)

    Q2      (o o o o)

    Q3      (o o o o)


    Q10    (o o o o)

    Here  (o o o o) is a radio button list.

    Now lets say user rate Question number Q1,Q4,Q6  as 1,3,4 then the answer would be stored in Sharepoint column would  be like 

    <Question Text>;#<Rating Number>#

    So Here in current example it would be like 


    Sample Code Would be like 

     SPListItem item = surveyList.AddItem();
                        string strResponse = string.Empty;
                        RadioButtonList a = new RadioButtonList();
                        foreach (RepeaterItem repeated in RepDetails.Items)
                            RadioButtonList rdlist = repeated.FindControl("RadioButtonList") as RadioButtonList;
                            string selectedval = rdlist.SelectedValue;
                            Label lblQuestion = (Label)repeated.FindControl("lblQuestion");
                            if (rdlist.SelectedItem != null)
                                strResponse += lblQuestion.Text + ";#" + rdlist.SelectedValue + "#";
                        item[QuestionText] = strResponse;


    • Edited by Airwings Tuesday, November 5, 2013 6:47 AM Typo
    • Marked as answer by Patrick_Liang Thursday, November 7, 2013 2:07 PM
    Tuesday, November 5, 2013 6:46 AM