private void RowsDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            TextBox updatedChildText = ((TextBox)e.Item.Cells[0].Controls[0]);

            if (updatedChildText.Text.Length == 0)
            {
                MessageLabel.Visible = true;
                ((PageBase)Page).ShowErrorMessage(MessageLabel, ((PageBase)Page).GetPageResource("RowMissingQuestionMessage"));
            }
            else
            {
                MatrixChildQuestionData childQuestion = new MatrixChildQuestionData();
                MatrixChildQuestionData.ChildQuestionsRow updatedChildQuestion =
                    childQuestion.ChildQuestions.NewChildQuestionsRow();
                updatedChildQuestion.QuestionId =
                    int.Parse(RowsDataGrid.DataKeys[e.Item.ItemIndex].ToString());
                updatedChildQuestion.QuestionText = updatedChildText.Text;
                childQuestion.ChildQuestions.AddChildQuestionsRow(updatedChildQuestion);
                new Question().UpdateChildQuestion(childQuestion, ChildsLanguageDropdownlist.SelectedValue);
                RowsDataGrid.EditItemIndex = -1;
                BindChildQuestions();
                MessageLabel.Visible = true;
                ((PageBase)Page).ShowNormalMessage(MessageLabel, ((PageBase)Page).GetPageResource("MatrixRowUpdatedMessage"));
            }
        }
        /// <summary>
        /// Converts a stronlgy typed MatrixChildQuestionData dataset
        /// to a webcontrol collection
        /// </summary>
        /// <param name="childQuestions">The questions / answers data</param>
        /// <param name="parentControlUniqueID">
        /// Unique ID required to identify global groups
        /// like radiobutton groups
        /// </param>
        /// <returns>a web control collection of MatrixChildQuestion</returns>
        public static MatrixChildCollection CreateQuestionChildCollection(MatrixChildQuestionData childQuestions, Section sectionContainer, string languageCode, string parentControlUniqueID, AnswerSelectionMode selectionMode, Style answerStyle, ControlRenderMode renderMode, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableAnswersDefault)
        {
            MatrixChildCollection childs = new MatrixChildCollection();

            foreach (MatrixChildQuestionData.ChildQuestionsRow row in childQuestions.ChildQuestions.Rows)
            {
                MatrixChildQuestion question = new MatrixChildQuestion();
                question.QuestionId = row.QuestionId;
                question.Text       = new PipeManager().PipeValuesInText(row.QuestionId, row.QuestionText, voterAnswersState, languageCode);
                AnswerData answers = new AnswerData();

//                answers.Merge(row.GetAnswersRows());

                MatrixChildQuestionData.AnswersRow[] ar = row.GetAnswersRows();
                foreach (MatrixChildQuestionData.AnswersRow r in ar)
                {
                    r.Table.Namespace = answers.Namespace;
                }
                answers.Merge(ar);

                question.Answers = AnswerItemFactory.CreateAnswerItemCollection(answers, question, sectionContainer, selectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, false, voterAnswersState, enableAnswersDefault);
                childs.Add(question);
            }
            return(childs);
        }
        /// <summary>
        /// Parse an MatrixChildCollection, converts the data
        /// to webcontrols and returns a filled matrix section
        /// </summary>
        protected virtual MatrixSection GetMatrixSection(MatrixChildQuestionData childQuestions, int sectionNumber, int sectionUid)
        {
            MatrixSection sectionContainer = new MatrixSection();

            sectionContainer.SectionUid     = sectionUid;
            sectionContainer.SectionNumber  = sectionNumber;
            sectionContainer.ChildQuestions = QuestionItemFactory.CreateQuestionChildCollection(childQuestions, sectionContainer, base.LanguageCode, this.UniqueID + GlobalConfig.AnswerSectionName + sectionUid, AnswerSelectionMode.Radio, base.AnswerStyle, base.RenderMode, base.VoterAnswersState, base.EnableAnswersDefault);
            return(sectionContainer);
        }
        private void BindChildQuestions()
        {
            MatrixChildQuestionData childQuestions = new MatrixChildQuestionData();

            childQuestions            = new Questions().GetMatrixChildQuestions(_parentQuestionId, ChildsLanguageDropdownlist.SelectedValue);
            RowsDataGrid.DataSource   = childQuestions;
            RowsDataGrid.DataMember   = "ChildQuestions";
            RowsDataGrid.DataKeyField = "QuestionID";
            RowsDataGrid.DataBind();
        }
        private void AddRowButton_Click(object sender, System.EventArgs e)
        {
            if (NewRowTextBox.Text.Length == 0)
            {
                MessageLabel.Visible = true;
                ((PageBase)Page).ShowErrorMessage(MessageLabel, ((PageBase)Page).GetPageResource("RowMissingQuestiondMessage"));
            }
            else
            {
                MatrixChildQuestionData childQuestion = new MatrixChildQuestionData();
                MatrixChildQuestionData.ChildQuestionsRow updatedChildQuestion =
                    childQuestion.ChildQuestions.NewChildQuestionsRow();
                updatedChildQuestion.ParentQuestionId = _parentQuestionId;
                updatedChildQuestion.QuestionText     = NewRowTextBox.Text;
                childQuestion.ChildQuestions.AddChildQuestionsRow(updatedChildQuestion);
                new Question().AddChildQuestion(childQuestion);

                BindChildQuestions();
                MessageLabel.Visible = true;
                ((PageBase)Page).ShowNormalMessage(MessageLabel, ((PageBase)Page).GetPageResource("MatrixRowAddedMessage"));

                NewRowTextBox.Text = string.Empty;
            }
        }
 /// <summary>
 /// Update the child question in the database
 /// </summary>
 /// <param name="updatedChildQuestion">question to update, must contain the question id</param>
 public void UpdateChildQuestion(MatrixChildQuestionData updatedChildQuestion, string languageCode)
 {
     QuestionFactory.Create().UpdateChildQuestion(updatedChildQuestion, languageCode);
 }
 /// <summary>
 /// Adds a new child question to the parent question specified by the parent questio id in the database
 /// </summary>
 /// <param name="newChildQuestion">Question object with information about what to add. Only Id must be ommited</param>
 public void AddChildQuestion(MatrixChildQuestionData newChildQuestion)
 {
     QuestionFactory.Create().AddChildQuestion(newChildQuestion);
 }