internal override void BuildNavigation(TableCell cell)
        {
            int index = 0;

            // Previous
            System.Web.UI.WebControls.LinkButton previous = new System.Web.UI.WebControls.LinkButton();
            if (this.CurrentPage == 0)
            {
                previous.Enabled = false;
            }
            previous.CausesValidation = this.CausesValidation;
            previous.Click           += new EventHandler(OnPreviousPage_Click);
            previous.Text             = PreviousText;
            cell.Controls.Add(previous);

            cell.Controls.Add(new LiteralControl(NavSeparator));

            if (this.PageSelectorEnabled)
            {
                System.Web.UI.WebControls.DropDownList pageSelector = new System.Web.UI.WebControls.DropDownList();

                pageSelector.ApplyStyle(this.SelectorStyle);

                for (index = 0; index < this.PagerElements.Count; index++)
                {
                    ListItem item = new ListItem(this.PagerElements[index].Label, this.PagerElements[index].Key);
                    if (index == this.CurrentPage)
                    {
                        item.Selected = true;
                    }

                    pageSelector.Items.Add(item);
                }

                pageSelector.AutoPostBack          = true;
                pageSelector.SelectedIndexChanged += new EventHandler(OnGotoPage_Click);
                cell.Controls.Add(pageSelector);

                cell.Controls.Add(new LiteralControl(NavSeparator));
            }

            // Group
            if (this.PagerElements.Count != 0)
            {
                cell.Controls.Add(new LiteralControl(PageGroupLeftSeparator));
            }

            for (index = 0; index < this.PagerElements.Count; index++)
            {
                if (index != CurrentPage)
                {
                    System.Web.UI.WebControls.LinkButton gotoPage = new System.Web.UI.WebControls.LinkButton();
                    gotoPage.CausesValidation = CausesValidation;
                    gotoPage.Click           += new EventHandler(OnGotoPage_Click);
                    gotoPage.Text             = this.PagerElements[index].Label;
                    gotoPage.CommandArgument  = this.PagerElements[index].Key;
                    cell.Controls.Add(gotoPage);
                }
                else
                {
                    cell.Controls.Add(new LiteralControl("<b>" + this.PagerElements[index].Label + "</b>"));
                }

                if (index != this.PagerElements.Count - 1)
                {
                    cell.Controls.Add(new LiteralControl("&nbsp;"));
                }
            }


            if (this.PagerElements.Count != 0)
            {
                cell.Controls.Add(new LiteralControl(PageGroupRightSeparator));
            }

            cell.Controls.Add(new LiteralControl(NavSeparator));

            // Next
            System.Web.UI.WebControls.LinkButton next = new System.Web.UI.WebControls.LinkButton();
            if (CurrentPage >= this.PagerElements.Count - 1)
            {
                next.Enabled = false;
            }
            next.CausesValidation = CausesValidation;
            next.Click           += new EventHandler(OnNextPage_Click);
            next.Text             = NextText;
            cell.Controls.Add(next);
        }
        /// <summary>
        /// Builds the navigation.
        /// </summary>
        /// <param name="cell">The cell.</param>
        internal override void BuildNavigation(TableCell cell)
        {
            string navigationTemplate = (this.RecordCount == 0 && !string.IsNullOrEmpty(NavigationTemplateNoRecords) ? NavigationTemplateNoRecords : NavigationTemplate);

            // Prepare the navigation template for parsing
            string strongSeparator = "{nctrl}";

            navigationTemplate = navigationTemplate.Replace("$PAGESIZES$", "{nctrl}$PAGESIZE${nctrl}");
            navigationTemplate = navigationTemplate.Replace("$PREVIOUSPAGE$", "{nctrl}$PREVIOUSPAGE${nctrl}");
            navigationTemplate = navigationTemplate.Replace("$FIRSTPAGE$", "{nctrl}$FIRSTPAGE${nctrl}");
            navigationTemplate = navigationTemplate.Replace("$PAGESELECTOR$", "{nctrl}$PAGESELECTOR${nctrl}");
            navigationTemplate = navigationTemplate.Replace("$PAGEGROUP$", "{nctrl}$PAGEGROUP${nctrl}");
            navigationTemplate = navigationTemplate.Replace("$LASTPAGE$", "{nctrl}$LASTPAGE${nctrl}");
            navigationTemplate = navigationTemplate.Replace("$NEXTPAGE$", "{nctrl}$NEXTPAGE${nctrl}");

            string[] stringSeparators = new string[] { strongSeparator };

            // Parse
            foreach (string templateItem in navigationTemplate.Split(stringSeparators, StringSplitOptions.None))
            {
                switch (templateItem)
                {
                case "$PAGESIZES$":
                    if (this.PageSizes != string.Empty)
                    {
                        DropDownList pageSizeSelector = new DropDownList();

                        pageSizeSelector.ApplyStyle(this.SelectorStyle);

                        foreach (string pageSize in this.PageSizes.Split(','))
                        {
                            ListItem item = new ListItem(pageSize, pageSize);
                            if (pageSize == this.PageSize.ToString())
                            {
                                item.Selected = true;
                            }

                            pageSizeSelector.Items.Add(item);
                        }

                        pageSizeSelector.AutoPostBack          = true;
                        pageSizeSelector.SelectedIndexChanged += new EventHandler(OnPageSize_Changed);
                        cell.Controls.Add(pageSizeSelector);
                    }
                    break;

                case "$PREVIOUSPAGE$":
                    LinkButton previous = new LinkButton();
                    if (this.CurrentIndex == 0)
                    {
                        previous.Enabled = false;
                    }
                    previous.CausesValidation = this.CausesValidation;
                    previous.Click           += new EventHandler(OnPreviousPage_Click);
                    previous.Text             = PreviousText;
                    cell.Controls.Add(previous);
                    break;

                case "$NEXTPAGE$":
                    // Next
                    LinkButton next = new LinkButton();
                    if (CurrentIndex >= RecordCount - PageSize)
                    {
                        next.Enabled = false;
                    }
                    next.CausesValidation = CausesValidation;
                    next.Click           += new EventHandler(OnNextPage_Click);
                    next.Text             = NextText;
                    cell.Controls.Add(next);
                    break;

                case "$FIRSTPAGE$":
                    if (!this.FirstLastDisabled)
                    {
                        // First
                        System.Web.UI.WebControls.LinkButton first = new System.Web.UI.WebControls.LinkButton();
                        if (this.CurrentIndex == 0)
                        {
                            first.Enabled = false;
                        }
                        first.CausesValidation = CausesValidation;
                        first.Click           += new EventHandler(OnFirstPage_Click);
                        first.Text             = _firstText;
                        cell.Controls.Add(first);
                    }
                    break;

                case "$LASTPAGE$":
                    if (!this.FirstLastDisabled)
                    {
                        // Last
                        System.Web.UI.WebControls.LinkButton last = new System.Web.UI.WebControls.LinkButton();
                        if (CurrentIndex >= RecordCount - PageSize)
                        {
                            last.Enabled = false;
                        }
                        last.CausesValidation = CausesValidation;
                        last.Click           += new EventHandler(OnLastPage_Click);
                        last.Text             = _lastText;
                        cell.Controls.Add(last);
                    }
                    break;

                case "$PAGESELECTOR$":
                    if (this.PageSelectorEnabled)
                    {
                        System.Web.UI.WebControls.DropDownList pageSelector = new System.Web.UI.WebControls.DropDownList();

                        pageSelector.ApplyStyle(this.SelectorStyle);

                        for (int index = 1; index <= this.PageCount; index++)
                        {
                            ListItem item = new ListItem(index.ToString(), index.ToString());
                            if (index == this.CurrentPage)
                            {
                                item.Selected = true;
                            }

                            pageSelector.Items.Add(item);
                        }

                        pageSelector.AutoPostBack          = true;
                        pageSelector.SelectedIndexChanged += new EventHandler(OnGotoPage_Click);
                        cell.Controls.Add(pageSelector);
                    }
                    break;

                case "$PAGEGROUP$":
                    if (!this.PageGroupDisabled)
                    {
                        // Calculate start & end positions
                        int start, end, index;

                        start = CurrentPage - 2;     // autoshift page groups

                        if (start < 1)
                        {
                            start = 1;     // but only for page selection over the shift factor
                        }
                        end = start + 9;   // Setup the end

                        if (end > PageCount)
                        {
                            end = PageCount;     // But only if page number is lower
                        }
                        if (PageCount >= 10 && (end - start) != 9)
                        {
                            start = end - 9;
                        }

                        // Build the output
                        if (!this.PreviousNextGroupDisabled)
                        {
                            System.Web.UI.WebControls.LinkButton prevPage = new System.Web.UI.WebControls.LinkButton();
                            if (CurrentGroup == 1)
                            {
                                prevPage.Enabled = false;
                            }
                            prevPage.CausesValidation = CausesValidation;
                            prevPage.Text             = "&lt;";
                            prevPage.Click           += new EventHandler(OnPreviousGroup_Click);
                            cell.Controls.Add(prevPage);
                        }

                        if (this.RecordCount != 0)
                        {
                            cell.Controls.Add(new LiteralControl(PageGroupLeftSeparator));
                        }

                        for (index = start; index <= end; index++)
                        {
                            if (index != CurrentPage)
                            {
                                System.Web.UI.WebControls.LinkButton gotoPage = new System.Web.UI.WebControls.LinkButton();
                                gotoPage.CausesValidation = CausesValidation;
                                gotoPage.Click           += new EventHandler(OnGotoPage_Click);
                                gotoPage.Text             = index.ToString();
                                cell.Controls.Add(gotoPage);
                            }
                            else
                            {
                                cell.Controls.Add(new LiteralControl("<b>" + index.ToString() + "</b>"));
                            }

                            if (index != end)
                            {
                                cell.Controls.Add(new LiteralControl("&nbsp;"));
                            }
                        }

                        if (this.RecordCount != 0)
                        {
                            cell.Controls.Add(new LiteralControl(PageGroupRightSeparator));
                        }

                        if (!this.PreviousNextGroupDisabled)
                        {
                            System.Web.UI.WebControls.LinkButton nextPage = new System.Web.UI.WebControls.LinkButton();
                            if (this.RecordCount == 0 || (CurrentGroup == (PageCount + 9) / 10))
                            {
                                nextPage.Enabled = false;
                            }
                            nextPage.CausesValidation = CausesValidation;
                            nextPage.Text             = "&gt;";
                            nextPage.Click           += new EventHandler(OnNextGroup_Click);
                            cell.Controls.Add(nextPage);
                        }
                    }
                    break;

                case "": break;

                default:
                    LiteralControl control = new LiteralControl();
                    control.Text = templateItem;
                    cell.Controls.Add(control);
                    break;
                }
            }
        }
Exemplo n.º 3
0
        protected override void RenderFooter(HtmlTextWriter writer) {
            writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "4px");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            DropDownList zonesDropDownList = new DropDownList();
            zonesDropDownList.ClientIDMode = ClientIDMode.AutoID;
            zonesDropDownList.ID = ZonesID;

            // Populate the DropDownList
            if (DesignMode) {
                // Add sample zone to dropdown
                zonesDropDownList.Items.Add(SR.GetString(SR.Zone_SampleHeaderText));
            }
            else {
                if (WebPartManager != null && WebPartManager.Zones != null) {
                    foreach (WebPartZoneBase zone in WebPartManager.Zones) {
                        if (zone.AllowLayoutChange) {
                            Debug.Assert(!String.IsNullOrEmpty(zone.ID));
                            ListItem item = new ListItem(zone.DisplayTitle, zone.ID);
                            if (String.Equals(zone.ID, _selectedZoneID, StringComparison.OrdinalIgnoreCase)) {
                                item.Selected = true;
                            }
                            zonesDropDownList.Items.Add(item);
                        }
                    }
                }
            }

            LabelStyle.AddAttributesToRender(writer, this);
            // Only render the "for" attribute if we are going to render the associated DropDownList (VSWhidbey 541458)
            if (zonesDropDownList.Items.Count > 0) {
                writer.AddAttribute(HtmlTextWriterAttribute.For, zonesDropDownList.ClientID);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Label);
            writer.Write(SelectTargetZoneText);
            writer.RenderEndTag();

            // Render &nbsp; before the DropDownList (VSWhidbey 77709)
            writer.Write("&nbsp;");

            zonesDropDownList.ApplyStyle(EditUIStyle);
            // Do not render empty DropDownList (VSWhidbey 534498)
            if (zonesDropDownList.Items.Count > 0) {
                zonesDropDownList.RenderControl(writer);
            }

            writer.Write("&nbsp;");

            RenderVerbs(writer);

            writer.RenderEndTag();  // Div
        }
 protected override void RenderFooter(HtmlTextWriter writer)
 {
     writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "4px");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     DropDownList list = new DropDownList {
         ClientIDMode = ClientIDMode.AutoID,
         ID = this.ZonesID
     };
     if (base.DesignMode)
     {
         list.Items.Add(System.Web.SR.GetString("Zone_SampleHeaderText"));
     }
     else if ((base.WebPartManager != null) && (base.WebPartManager.Zones != null))
     {
         foreach (WebPartZoneBase base2 in base.WebPartManager.Zones)
         {
             if (base2.AllowLayoutChange)
             {
                 ListItem item = new ListItem(base2.DisplayTitle, base2.ID);
                 if (string.Equals(base2.ID, this._selectedZoneID, StringComparison.OrdinalIgnoreCase))
                 {
                     item.Selected = true;
                 }
                 list.Items.Add(item);
             }
         }
     }
     base.LabelStyle.AddAttributesToRender(writer, this);
     if (list.Items.Count > 0)
     {
         writer.AddAttribute(HtmlTextWriterAttribute.For, list.ClientID);
     }
     writer.RenderBeginTag(HtmlTextWriterTag.Label);
     writer.Write(this.SelectTargetZoneText);
     writer.RenderEndTag();
     writer.Write("&nbsp;");
     list.ApplyStyle(base.EditUIStyle);
     if (list.Items.Count > 0)
     {
         list.RenderControl(writer);
     }
     writer.Write("&nbsp;");
     this.RenderVerbs(writer);
     writer.RenderEndTag();
 }