protected override void Render(HtmlTextWriter output)
        {
            var whereCls = new List <Func <RoleInfo, bool> >
            {
                grp => grp.SecurityMode != SecurityMode.SecurityRole && grp.Status == RoleStatus.Approved
            };

            if (RoleGroupId >= -1)
            {
                whereCls.Add(grp => grp.RoleGroupID == RoleGroupId);
            }

            if (DisplayCurrentUserGroups)
            {
                whereCls.Add(grp => currentUser.IsInRole(grp.RoleName));
            }
            else
            {
                whereCls.Add(grp => grp.IsPublic || currentUser.IsInRole(grp.RoleName) || currentUser.IsInRole(PortalSettings.AdministratorRoleName));
            }

            if (!string.IsNullOrEmpty(SearchFilter))
            {
                whereCls.Add(grp => grp.RoleName.ToLowerInvariant().Contains(SearchFilter.ToLowerInvariant()) || grp.Description.ToLowerInvariant().Contains(SearchFilter.ToLowerInvariant()));
            }

            var roles = RoleController.Instance.GetRoles(PortalSettings.PortalId, grp => TestPredicateGroup(whereCls, grp));

            if (SortDirection.ToLowerInvariant() == "asc")
            {
                roles = roles.OrderBy(info => GetOrderByProperty(info, SortField)).ToList();
            }
            else
            {
                roles = roles.OrderByDescending(info => GetOrderByProperty(info, SortField)).ToList();
            }

            decimal pages = (decimal)roles.Count / (decimal)PageSize;


            output.Write(HeaderTemplate);


            ItemTemplate = ItemTemplate.Replace("{resx:posts}", Localization.GetString("posts", Constants.SharedResourcesPath));
            ItemTemplate = ItemTemplate.Replace("{resx:members}", Localization.GetString("members", Constants.SharedResourcesPath));
            ItemTemplate = ItemTemplate.Replace("{resx:photos}", Localization.GetString("photos", Constants.SharedResourcesPath));
            ItemTemplate = ItemTemplate.Replace("{resx:documents}", Localization.GetString("documents", Constants.SharedResourcesPath));

            ItemTemplate = ItemTemplate.Replace("{resx:Join}", Localization.GetString("Join", Constants.SharedResourcesPath));
            ItemTemplate = ItemTemplate.Replace("{resx:Pending}", Localization.GetString("Pending", Constants.SharedResourcesPath));
            ItemTemplate = ItemTemplate.Replace("{resx:LeaveGroup}", Localization.GetString("LeaveGroup", Constants.SharedResourcesPath));
            ItemTemplate = ItemTemplate.Replace("[GroupViewTabId]", GroupViewTabId.ToString());

            if (roles.Count == 0)
            {
                output.Write(String.Format("<div class=\"dnnFormMessage dnnFormInfo\"><span>{0}</span></div>", Localization.GetString("NoGroupsFound", Constants.SharedResourcesPath)));
            }


            if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["page"]))
            {
                CurrentIndex = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"].ToString());
                CurrentIndex = CurrentIndex - 1;
            }

            int rowItem     = 0;
            int recordStart = (CurrentIndex * PageSize);

            if (CurrentIndex == 0)
            {
                recordStart = 0;
            }


            for (int x = recordStart; x < (recordStart + PageSize); x++)
            {
                if (x > roles.Count - 1)
                {
                    break;
                }

                var role = roles[x];

                string rowTemplate = ItemTemplate;

                if (rowItem == 0)
                {
                    output.Write(RowHeaderTemplate);
                }

                var groupParser = new GroupViewParser(PortalSettings, role, currentUser, rowTemplate, GroupViewTabId);
                output.Write(groupParser.ParseView());

                rowItem += 1;

                if (rowItem == ItemsPerRow)
                {
                    output.Write(RowFooterTemplate);
                    rowItem = 0;
                }
            }

            if (rowItem > 0)
            {
                output.Write(RowFooterTemplate);
            }


            output.Write(FooterTemplate);

            int TotalPages = Convert.ToInt32(System.Math.Ceiling(pages));


            if (TotalPages == 0)
            {
                TotalPages = 1;
            }

            string sUrlFormat = "<a href=\"{0}\" class=\"{1}\">{2}</a>";

            string[] currParams = new string[] { };

            StringBuilder sb = new StringBuilder();

            if (TotalPages > 1)
            {
                for (int x = 1; x <= TotalPages; x++)
                {
                    string[] @params = new string[] { };

                    if (currParams.Length > 0 & x > 1)
                    {
                        @params = Utilities.AddParams("page=" + x.ToString(), currParams);
                    }
                    else if (currParams.Length > 0 & x == 1)
                    {
                        @params = currParams;
                    }
                    else if (x > 1)
                    {
                        @params = new string[] { "page=" + x.ToString() };
                    }

                    string sUrl = Utilities.NavigateUrl(TabId, @params);

                    string cssClass = "pagerItem";

                    if (x - 1 == CurrentIndex)
                    {
                        cssClass = "pagerItemSelected";
                    }


                    sb.AppendFormat(sUrlFormat, sUrl, cssClass, x.ToString());
                }
            }

            output.Write("<div class=\"dnnClear groupPager\">");
            output.Write(sb.ToString());
            output.Write("</div>");
        }