示例#1
0
    /// <summary>
    /// Handles events that occur when an edit operation is requested, but before the Update Subquestions ListView item is put in edit mode.
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Provides data for the ItemEditing event, which occurs when an edit operation is requested but before the ListView item is put in edit mode.</param>
    protected void UpdateSubQuestionsListView_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        //hide message user control
        MessageUserControl.Visible = false;

        //hide datapager
        DataPager pager = UpdateSubQuestionsListView.FindControl("ActiveDataPager") as DataPager;

        pager.Visible = false;
    }
示例#2
0
    /// <summary>
    /// Handles events that occur when a button in the Subquestions list view is clicked
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Provides data for the ItemCommand event, which occurs when a button in a ListView is clicked.</param>
    protected void UpdateSubQuestionsListView_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        //If the Edit button is clicked, do the following actions:
        if (e.CommandName.Equals("Edit"))
        {
            //show informational message
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfo("Edit Mode Active", "The subquestion text in the selected row can now be edited.");

            //disable drop-down list and fetch button to prevent editing of subquestions of other questions
            QuestionsWithSubQuestionsDropDownList.Enabled = false;
            FetchSubQuestionsButton.Enabled = false;
        }
        //If the Change button is clicked, do the following actions:
        else if (e.CommandName.Equals("Change"))
        {
            //capture the questionId associated to the selected subquestion
            int questionId = int.Parse(e.CommandArgument.ToString());

            //capture the display index
            int i = e.Item.DisplayIndex;

            //find the selected subquestion text box
            TextBox subQuestionTextBox = UpdateSubQuestionsListView.Items[i].FindControl("subQuestionTextTextBox") as TextBox;

            //capture the question text in the selected subquestion text box
            string subQuestionText = subQuestionTextBox.Text;

            //handle null values and white-space-only values
            if (string.IsNullOrEmpty(subQuestionText) || string.IsNullOrWhiteSpace(subQuestionText))
            {
                //show error message
                MessageUserControl.Visible = true;
                MessageUserControl.ShowInfoError("Processing Error", "Subquestion is required.");

                //highlight the subquestion row that caused the error
                subQuestionTextBox.Focus();
            }
            //if user-entered value is not null or just a white space, do the the following actions:
            else
            {
                MessageUserControl.TryRun(() =>
                {
                    //check if user entered invalid values
                    Utility utility = new Utility();
                    utility.checkValidString(subQuestionText);

                    //update the subquestion text of the selected row
                    QuestionController sysmgr = new QuestionController();
                    sysmgr.SubQuestion_Update(questionId, subQuestionText);
                    UpdateSubQuestionsListView.DataBind();
                    UpdateSubQuestionsListView.EditIndex = -1;
                }, "Success", "Subquestion has been updated.");
            }

            //show success/error message
            MessageUserControl.Visible = true;

            //show datapager
            DataPager pager = UpdateSubQuestionsListView.FindControl("ActiveDataPager") as DataPager;
            pager.Visible = true;

            //enable drop-down list and fetch button to allow editing of other subquestions of other questions
            QuestionsWithSubQuestionsDropDownList.Enabled = true;
            FetchSubQuestionsButton.Enabled = true;
        }
        //If the Cancel button is clicked, do the following actions:
        else if (e.CommandName.Equals("Cancel"))
        {
            //show informational message
            MessageUserControl.Visible = true;
            MessageUserControl.ShowInfo("Update Cancelled", "No changes to the selected subquestion were saved.");

            //show datapager
            DataPager pager = UpdateSubQuestionsListView.FindControl("ActiveDataPager") as DataPager;
            pager.Visible = true;

            //enable drop-down list and fetch button to allow editing of other subquestions of other questions
            QuestionsWithSubQuestionsDropDownList.Enabled = true;
            FetchSubQuestionsButton.Enabled = true;
        }
    }