private void BindQuestionGroups()
        {
            QuestionData question = new Questions().GetQuestionById(_parentQuestionId, LanguagesDropdownlist.SelectedValue);
            QuestionData.QuestionsRow questionRow = question.Questions[0];
            int questionGroupId = questionRow.IsQuestionGroupIDNull() ? -1 : (int)questionRow.QuestionGroupID;

            int selectedQuestionGroupId = -1;

            QuestionGroupsData data = new Votations.NSurvey.DataAccess.QuestionGroups().GetAll(LanguagesDropdownlist.SelectedValue);
            DataView groupView = data.DefaultViewManager.CreateDataView(data.Tables[0]);
            DataView subGroupView = data.DefaultViewManager.CreateDataView(data.Tables[0]);
            groupView.RowFilter = "ParentGroupId is null";


            foreach (QuestionGroupsData.QuestionGroupsRow row in data.Tables[0].Rows)
            {
                if (row.ID == questionGroupId)
                {
                    selectedQuestionGroupId = (row.ParentGroupID != null) ? (int)row.ParentGroupID : questionGroupId;
                    break;
                }
            }


            if (ddlGroup.SelectedIndex > -1 && ddlGroup.SelectedValue != selectedQuestionGroupId.ToString())
                selectedQuestionGroupId = int.Parse(ddlGroup.SelectedValue);

            subGroupView.RowFilter = "ParentGroupId = " + selectedQuestionGroupId;
            ddlGroup.Items.Clear();
            ddlGroup.Items.Add(new ListItem("-Select-", "-1"));
            ddlSubGroup.Items.Clear();
            ddlSubGroup.Items.Add(new ListItem("-Select-", "-1"));

            ddlGroup.DataSource = groupView;
            ddlGroup.DataTextField = "GroupName";
            ddlGroup.DataValueField = "ID";
            ddlGroup.DataBind();

            ddlSubGroup.DataSource = subGroupView;
            ddlSubGroup.DataTextField = "GroupName";
            ddlSubGroup.DataValueField = "ID";
            ddlSubGroup.DataBind();

            foreach (ListItem item in ddlGroup.Items)
            {
                if (item.Value == selectedQuestionGroupId.ToString())
                {
                    item.Selected = true;
                    break;
                }
            }

            foreach (ListItem item in ddlSubGroup.Items)
            {
                if (item.Value == questionGroupId.ToString())
                {
                    item.Selected = true;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        void BindFields()
        {
            DataView           dv;
            QuestionGroupsData groups = new Votations.NSurvey.DataAccess.QuestionGroups().GetAll(ddlLanguage.SelectedValue);

            dv           = groups.DefaultViewManager.CreateDataView(groups.Tables[0]);
            dv.RowFilter = "ParentGroupId =-1 or parentGroupId is null ";
            dv.Sort      = "DisplayOrder asc";


            // when no results found we add new empty row and clear it cells
            if (dv.Count == 0)
            {
                if (gvGroups.ShowFooter)
                {
                    dv.AddNew();
                    gvGroups.DataSource = dv;

                    gvGroups.DataBind();
                    foreach (TableCell cell in gvGroups.Rows[0].Cells)
                    {
                        cell.Controls.Clear();
                        cell.Controls.Add(new Literal());
                    }
                    gvGroups.Rows[0].Visible = false;
                    gvSubGroup.Visible       = false;
                    gvGroups.Visible         = true;
                }
                else
                {
                    gvSubGroup.Visible = false;
                    gvGroups.Visible   = false;
                }
                return;
            }
            gvGroups.Visible    = true;
            gvSubGroup.Visible  = true;
            gvGroups.DataSource = dv;
            gvGroups.DataBind();

            if ((SelectedGroupID < 0) && (dv.Table.Rows.Count > 0))
            {
                SelectedGroupID = ((QuestionGroupsData.QuestionGroupsRow)dv[0].Row).ID;
            }

            foreach (GridViewRow row in gvGroups.Rows)
            {
                if (((QuestionGroupsData.QuestionGroupsRow)dv[row.DataItemIndex].Row).ID == SelectedGroupID)
                {
                    RadioButton rb = (RadioButton)row.FindControl("rbButton");
                    rb.Checked = true;
                    if (lblGroupName.Text == string.Empty)
                    {
                        lblGroupName.Text = ((QuestionGroupsData.QuestionGroupsRow)dv[0].Row).GroupName;
                    }
                    break;
                }
            }

            DataView dv1 = groups.DefaultViewManager.CreateDataView(groups.Tables[0]);

            dv1.RowFilter = "ParentGroupId = " + SelectedGroupID.ToString();
            dv1.Sort      = "DisplayOrder asc";

            // when no results found we add new empty row and clear it cells
            if (dv1.Count == 0)
            {
                dv1.AddNew();
                gvSubGroup.DataSource = dv1;
                gvSubGroup.DataBind();
                foreach (TableCell cell in gvSubGroup.Rows[0].Cells)
                {
                    cell.Controls.Clear();
                    cell.Controls.Add(new Literal());
                }
            }
            else
            {
                gvSubGroup.DataSource = dv1;
                gvSubGroup.DataBind();
            }
        }
Ejemplo n.º 3
0
        private void BindQuestionGroups()
        {
            QuestionData question = new Questions().GetQuestionById(_questionId, LanguagesDropdownlist.SelectedValue);

            QuestionData.QuestionsRow questionRow = question.Questions[0];
            int questionGroupId = questionRow.IsQuestionGroupIDNull() ? -1 : (int)questionRow.QuestionGroupID;

            int selectedQuestionGroupId = -1;

            QuestionGroupsData data         = new Votations.NSurvey.DataAccess.QuestionGroups().GetAll(LanguagesDropdownlist.SelectedValue);
            DataView           groupView    = data.DefaultViewManager.CreateDataView(data.Tables[0]);
            DataView           subGroupView = data.DefaultViewManager.CreateDataView(data.Tables[0]);

            groupView.RowFilter = "ParentGroupId is null";


            foreach (QuestionGroupsData.QuestionGroupsRow row in data.Tables[0].Rows)
            {
                if (row.ID == questionGroupId)
                {
                    selectedQuestionGroupId = (row.ParentGroupID != null) ? (int)row.ParentGroupID : questionGroupId;
                    break;
                }
            }


            if (ddlGroup.SelectedIndex > -1 && ddlGroup.SelectedValue != selectedQuestionGroupId.ToString())
            {
                selectedQuestionGroupId = int.Parse(ddlGroup.SelectedValue);
            }

            subGroupView.RowFilter = "ParentGroupId = " + selectedQuestionGroupId;
            ddlGroup.Items.Clear();
            ddlGroup.Items.Add(new ListItem(GetPageResource("DdlNoSelect"), "-1"));
            ddlSubGroup.Items.Clear();
            ddlSubGroup.Items.Add(new ListItem(GetPageResource("DdlNoSelect"), "-1"));

            ddlGroup.DataSource     = groupView;
            ddlGroup.DataTextField  = "GroupName";
            ddlGroup.DataValueField = "ID";
            ddlGroup.DataBind();

            ddlSubGroup.DataSource     = subGroupView;
            ddlSubGroup.DataTextField  = "GroupName";
            ddlSubGroup.DataValueField = "ID";
            ddlSubGroup.DataBind();

            foreach (ListItem item in ddlGroup.Items)
            {
                if (item.Value == selectedQuestionGroupId.ToString())
                {
                    item.Selected = true;
                    break;
                }
            }

            foreach (ListItem item in ddlSubGroup.Items)
            {
                if (item.Value == questionGroupId.ToString())
                {
                    item.Selected = true;
                    break;
                }
            }
        }
        void BindFields()
        {
            DataView dv;
            QuestionGroupsData groups = new Votations.NSurvey.DataAccess.QuestionGroups().GetAll(ddlLanguage.SelectedValue);
            dv = groups.DefaultViewManager.CreateDataView(groups.Tables[0]);
            dv.RowFilter = "ParentGroupId =-1 or parentGroupId is null ";
            dv.Sort = "DisplayOrder asc";


            // when no results found we add new empty row and clear it cells
            if (dv.Count == 0)
            {
                if (gvGroups.ShowFooter)
                {
                    dv.AddNew();
                    gvGroups.DataSource = dv;

                    gvGroups.DataBind();
                    foreach (TableCell cell in gvGroups.Rows[0].Cells)
                    {
                        cell.Controls.Clear();
                        cell.Controls.Add(new Literal());
                    }
                    gvGroups.Rows[0].Visible = false;
                    gvSubGroup.Visible = false;
                    gvGroups.Visible = true;
                }
                else
                {
                    gvSubGroup.Visible = false;
                    gvGroups.Visible = false;
                }
                return;
            }
            gvGroups.Visible = true;
            gvSubGroup.Visible = true;
            gvGroups.DataSource = dv;
            gvGroups.DataBind();

            if ((SelectedGroupID < 0) && (dv.Table.Rows.Count > 0))
            {
                SelectedGroupID = ((QuestionGroupsData.QuestionGroupsRow)dv[0].Row).ID;
            }

            foreach (GridViewRow row in gvGroups.Rows)
            {
                if (((QuestionGroupsData.QuestionGroupsRow)dv[row.DataItemIndex].Row).ID == SelectedGroupID)
                {
                    RadioButton rb = (RadioButton)row.FindControl("rbButton");
                    rb.Checked = true;
                    if (lblGroupName.Text == string.Empty)
                        lblGroupName.Text = ((QuestionGroupsData.QuestionGroupsRow)dv[0].Row).GroupName;
                    break;
                }
            }

            DataView dv1 = groups.DefaultViewManager.CreateDataView(groups.Tables[0]);
            dv1.RowFilter = "ParentGroupId = " + SelectedGroupID.ToString();
            dv1.Sort = "DisplayOrder asc";

            // when no results found we add new empty row and clear it cells
            if (dv1.Count == 0)
            {
                dv1.AddNew();
                gvSubGroup.DataSource = dv1;
                gvSubGroup.DataBind();
                foreach (TableCell cell in gvSubGroup.Rows[0].Cells)
                {
                    cell.Controls.Clear();
                    cell.Controls.Add(new Literal());
                }
            }
            else
            {
                gvSubGroup.DataSource = dv1;
                gvSubGroup.DataBind();
            }
        }