Exemple #1
0
    /// <summary>
    /// Load the survey page
    /// </summary>
    /// <param name="sender">User http request
    /// <param name="e">Page Load event
    protected void Page_Load(object sender, EventArgs e)
    {
        Stack <int> nextQuestionID = (Stack <int>)(Session["nextq"]);
        int         currentqid     = 1;

        if (Session["rid"] == null)
        {
            //generate new respondent ID
            Session["rid"] = dbAccess.GetNewRespondentID();
        }

        //First page load
        if (nextQuestionID == null)
        {
            //Load 1st question
            nextQuestionID = new Stack <int>();
            nextQuestionID.Push(1);
            Session["nextq"] = nextQuestionID;
        }
        else
        {
            currentqid = nextQuestionID.Peek();
        }

        //access the question from db
        question = dbAccess.GetQuestion(currentqid);

        //render the question and option controls accoring to question type
        if (question != null)
        {
            questionLbl.Text = question.question.ToString();
            switch (question.q_type)
            {
            case "rbl":
                rBoxList.ID       = "RBL";
                rBoxList.CssClass = "rblCss";

                List <Option> rboxOptList = dbAccess.GetOptions(question.q_id);
                if (rboxOptList != null)
                {
                    for (int i = 0; i < rboxOptList.Count; i++)
                    {
                        ListItem item = new ListItem();
                        item.Value = rboxOptList[i].opt_id.ToString();
                        item.Text  = rboxOptList[i].option.ToString();
                        if (rboxOptList[i].nq_id != null)
                        {
                            item.Attributes["nextQID"] = rboxOptList[i].nq_id.ToString();
                        }
                        rBoxList.Items.Add(item);
                    }
                }
                optHolder.Controls.Add(rBoxList);
                Session["qtype"] = rBoxList.ID;
                break;

            case "cbl":
                cBoxList.ID = "CBL";
                List <Option> cboxOptlist = dbAccess.GetOptions(question.q_id);
                if (cboxOptlist != null)
                {
                    for (int i = 0; i < cboxOptlist.Count; i++)
                    {
                        ListItem item = new ListItem();
                        item.Value = cboxOptlist[i].opt_id.ToString();
                        item.Text  = cboxOptlist[i].option.ToString();
                        if (cboxOptlist[i].nq_id != null)
                        {
                            item.Attributes["nextQID"] = cboxOptlist[i].nq_id.ToString();
                        }
                        cBoxList.Items.Add(item);
                    }
                }
                optHolder.Controls.Add(cBoxList);
                Session["qtype"] = rBoxList.ID;
                break;

            case "tb":
                tbox.ID = "TB";
                optHolder.Controls.Add(tbox);
                Session["qtype"] = rBoxList.ID;
                break;
            }
        }
    }