protected void Page_Load(object sender, EventArgs e)
        {
            _sqlHelper = new SqlHelper();

            try
            {
                _inBloomApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());
            }
            catch (Exception Ex)
            {
                Response.Redirect("Search.aspx");
            }

            if (!IsPostBack)
            {
                if (Session["CopyAggregateFlag"] != null)
                {
                    _aggregateFlagId = Convert.ToInt16(Session["CopyAggregateFlag"].ToString());

                    IList<AggregateFlag> _AggregateFlag = _sqlHelper.GetAggregateFlag(_aggregateFlagId);

                    txtFlagName.Text = _AggregateFlag[0].AggregateFlagName;
                    txtDescription.Text = _AggregateFlag[0].AggregateFlagDescription;
                    txtFlag.Text = _AggregateFlag[0].Keyword;

                    _user = (User)Session["UserDetail"];
                    if (_user == null)
                    {
                        Session[SessionEnum.AccessToken.ToString()] = null;
                        Response.Redirect("Search.aspx");
                    }
                    else
                    {
                        if (_user.IsAdminUser)
                        {
                            String IsPublic = _AggregateFlag[0].IsPublic.ToString();
                            if (IsPublic == "True")
                            {
                                radioFlagType.SelectedIndex = 0;
                            }
                            else
                            {
                                radioFlagType.SelectedIndex = 1;
                            }
                        }
                        else
                        {
                            PanelFlagType.Visible = false;
                        }

                        _user = (User)Session["UserDetail"];
                        //gridStudentInfo.DataSource = _sqlHelper.GetFlagList(_user.ExternalId);
                        //gridStudentInfo.DataBind();

                        IList<Flag> _flagForGrid = _sqlHelper.GetFlagList(_user.ExternalId);
                        IList<Flag> _flagListTemp = null;

                        String EducationOrganizationId = Session["EducationOrganizationId"].ToString();
                        String[] AdminUserId = _inBloomApi.GetAdminIdByEducationOrganizationId(EducationOrganizationId);
                        if (AdminUserId != null)
                        {
                            for (int i = 0; i < AdminUserId.Count(); i++)
                            {
                                _flagListTemp = _sqlHelper.GetPublicFlagListForAdmin(AdminUserId[i]);
                                if (_flagForGrid == null)
                                {
                                    _flagForGrid = _flagListTemp;
                                }
                                else
                                {
                                    for (int j = 0; j < _flagListTemp.Count; j++)
                                    {
                                        _flagForGrid.Add(_flagListTemp[j]);
                                    }

                                }
                            }
                        }

                        gridStudentInfo.DataSource = _flagForGrid;
                        gridStudentInfo.DataBind();

                        // add to listbox
                        IList<Flag> _flag = _sqlHelper.GetFlagAddedForInAggregate(_aggregateFlagId);
                        for (int i = 0; i < _flag.Count; i++)
                        {
                            int FlagId = _flag[i].FlagId;
                            String FlagName = _flag[i].FlagName;

                            lstcategory.Items.Add(new ListItem(FlagName, FlagId.ToString()));
                        }

                        foreach (GridViewRow row in gridStudentInfo.Rows)
                        {
                            int FlagId = Convert.ToInt16(row.Cells[4].Text);
                            for (int i = 0; i < _flag.Count; i++)
                            {
                                if (_flag[i].FlagId == FlagId)
                                {
                                    row.Visible = false;
                                    break;
                                }
                            }
                        }
                    }

                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _sqlHelper = new SqlHelper();

            try
            {
                _inBloomApi = new inBloomApi(Session[SessionEnum.AccessToken.ToString()].ToString());
            }
            catch (Exception Ex)
            {
                Response.Redirect("Search.aspx");
            }

            if (!IsPostBack)
            {

                 _user = (User)Session["UserDetail"];

                 if (_user == null)
                 {
                     Session[SessionEnum.AccessToken.ToString()] = null;
                     Response.Redirect("Search.aspx");
                 }
                 else
                 {
                     //gridStudentInfo.DataSource = _sDACEntities.Flags;
                     //gridStudentInfo.DataSource = _sqlHelper.GetFlagList(_user.ExternalId);
                     //gridStudentInfo.DataBind();

                     IList<Flag> _flag = _sqlHelper.GetFlagList(_user.ExternalId);

                     IList<Flag> _flagListTemp = null;

                     String EducationOrganizationId = Session["EducationOrganizationId"].ToString();
                     String[] AdminUserId = _inBloomApi.GetAdminIdByEducationOrganizationId(EducationOrganizationId);
                     if (AdminUserId != null)
                     {
                         for (int i = 0; i < AdminUserId.Count(); i++)
                         {
                             _flagListTemp = _sqlHelper.GetPublicFlagListForAdmin(AdminUserId[i]);
                             if (_flag == null)
                             {
                                 _flag = _flagListTemp;
                             }
                             else
                             {
                                 for (int j = 0; j < _flagListTemp.Count; j++)
                                 {
                                     _flag.Add(_flagListTemp[j]);
                                 }

                             }
                         }
                     }

                     gridStudentInfo.DataSource = _flag;

                     gridStudentInfo.DataBind();

                     if (_user.IsAdminUser)
                     {
                     }
                     else
                     {
                         PanelFlagType.Visible = false;
                     }

                 }

            }

            String script = "function abc() {" +

                         "var count = 0;" +
                         "$('#lstcategory option').each(function (e) {" +
                             "count = count + 1;" +
                         "});" +

                         "$('#gridStudentInfo tr input:checkbox').each(function () {" +

                             "if (this.checked) {" +
                                 "count = count + 1;" +
                             "}" +

                         "});" +

                         "if (count > 5) {" +

                             "DisplayErrorPopup('You can select only 5 flags.');" +
                             "return false;" +
                         "}" +

                         "return true;" +

                     "}";

            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), Guid.NewGuid().ToString(), script, true);
        }