Esempio n. 1
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            _chkAnswer = new CheckBoxList
            {
                ID = "chk" + _question.QuestionGuid.ToString().Replace("-", String.Empty)
            };

            Label lblQuestion = new Label
            {
                ID                  = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty),
                CssClass            = "settinglabel",
                Text                = _question.QuestionName,
                AssociatedControlID = _chkAnswer.ID
            };

            Literal litQuestionText = new Literal
            {
                Text = _question.QuestionText
            };

            CheckBoxListValidator valQuestion = new CheckBoxListValidator
            {
                ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty),
                ControlToValidate = _chkAnswer.ID,
                Enabled           = _question.AnswerIsRequired
            };

            string[] answers = _answer.Split(',');

            foreach (QuestionOption option in _options)
            {
                bool selected = false;

                foreach (string item in answers)
                {
                    if (option.Answer == item)
                    {
                        selected = true;
                        break;
                    }
                }

                ListItem li = new ListItem(option.Answer)
                {
                    Selected = selected
                };

                _chkAnswer.Items.Add(li);
            }

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(litQuestionText);
            Controls.Add(_chkAnswer);
            Controls.Add(valQuestion);
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Label lblQuestion = new Label();
            CheckBoxListValidator valQuestion = new CheckBoxListValidator();

            _chkAnswer = new CheckBoxList();

            lblQuestion.ID = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            _chkAnswer.ID  = "chk" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            valQuestion.ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty);

            lblQuestion.Text = _question.QuestionText;
            lblQuestion.AssociatedControlID = _chkAnswer.ID;

            valQuestion.ControlToValidate = _chkAnswer.ID;
            valQuestion.Enabled           = _question.AnswerIsRequired;

            string[] answers;
            answers = _answer.Split(',');

            foreach (QuestionOption option in _options)
            {
                bool selected = false;

                foreach (string item in answers)
                {
                    if (option.Answer == item)
                    {
                        selected = true;
                        break;
                    }
                }

                ListItem li = new ListItem(option.Answer);
                li.Selected = selected;

                _chkAnswer.Items.Add(li);
            }

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(_chkAnswer);
            Controls.Add(valQuestion);
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Label lblQuestion = new Label();
            CheckBoxListValidator valQuestion = new CheckBoxListValidator();
            _chkAnswer = new CheckBoxList();

            lblQuestion.ID = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            _chkAnswer.ID = "chk" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            valQuestion.ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty);

            lblQuestion.Text = _question.QuestionText;
            lblQuestion.AssociatedControlID = _chkAnswer.ID;

            valQuestion.ControlToValidate = _chkAnswer.ID;
            valQuestion.Enabled = _question.AnswerIsRequired;

            string[] answers;
            answers = _answer.Split(',');

            foreach (QuestionOption option in _options)
            {
                bool selected = false;

                foreach (string item in answers)
                {
                    if (option.Answer == item)
                    {
                        selected = true;
                        break;
                    }
                }

                ListItem li = new ListItem(option.Answer);
                li.Selected = selected;

                _chkAnswer.Items.Add(li);
            }

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(_chkAnswer);
            Controls.Add(valQuestion);
        }