learningdotnet 0 Newbie Poster

Hello All,
I currently have pager.ascx control which i am using to display 12 items per page. i am using "gid" constant string to set the number of pages. "gid" is defined in my base class called myPage.cs as follows

public class myPage : Page
{
    #region constants

    [B]protected const string REQ_PAGE_ID = "gid";[/B]
    
	// trying to add this just like above
	protected const string REQ_VIEWALL_ID = "allgid";

       #endregion
	   }

here is my code for the pager control

#region properties

    /// <summary>
    /// Gets or sets the current page of products to be displayed
    /// </summary>
    public int PageIndex
    {
        get 
        {
            object oPageIndex = ViewState[ "page_index" ];
            if ( oPageIndex == null )
            {
               [B] if ( Request[ "gid" ] != null )
                {
                    PageIndex = Convert.ToInt32( Request[ "gid" ] );
                }
                else
                {
                   PageIndex = 0;
                }[/B]
                return PageIndex;
            }
            
            return Convert.ToInt32( oPageIndex );
        }
        set
        {
            this.ViewState[ "page_index" ] = value;
        }
    }

    /// <summary>
    /// Gets or sets the maximum number of items to display at once
    /// </summary>
    public int PageSize
    {
        get { return Convert.ToInt32( ViewState[ "page_size" ] ); }
       // get { return (ViewState["page_size"] == "" ? 0 : Convert.ToInt32(ViewState["page_size"])); }
        set 
        { 
            this.ViewState[ "page_size" ] = value; 
        }
    }
   

    #endregion

    #region on init

    override protected void OnInit( EventArgs e )
    {
        base.OnInit( e );

        this.lbPrevious.Click += new EventHandler( lbPrevious_Click );
        this.lbNext.Click += new EventHandler( lbNext_Click );
        this.rPages.ItemDataBound += new RepeaterItemEventHandler( rPages_ItemDataBound );
        this.lbAll.Click += new EventHandler(lbAll_Click);
        this.lbviewbypage.Click += new EventHandler(lbviewbypage_Click);
    }
   

    #endregion

    #region page load

    protected void Page_Load( object sender, EventArgs e )
    {
        if ( !this.IsPostBack )
        {
            //this.SetPagingLabels( this.TotalRecords );
        }
    }

    #endregion

    #region pages data bound

    void rPages_ItemDataBound( object sender, RepeaterItemEventArgs e )
    {
               
        if ( e.Item.ItemType == ListItemType.AlternatingItem ||
             e.Item.ItemType == ListItemType.Item )
        {
            LinkButton lbPage = (LinkButton) e.Item.FindControl( "lbPage" );
            // subtract 1 to get zero based index (1-based index used for display)
            lbPage.Attributes.Add( "onmouseover", "return true;" ); 
            int CurrentPage = Convert.ToInt32( e.Item.DataItem ) - 1;
            if ( CurrentPage == this.PageIndex )
            {
                lbPage.Attributes.Add( "class", "current" );
            }
            lbPage.CommandArgument = CurrentPage.ToString( );
        }
    }

    #endregion

    #region pager clicks

    protected void lbPage_Click( object sender, EventArgs e )
    {
        this.PageIndex = Convert.ToInt32( ( (LinkButton) sender ).CommandArgument );
        RaisePagingEvent( sender );
    }

    void lbNext_Click( object sender, EventArgs e )
    {
        this.PageIndex++;
        RaisePagingEvent( sender );
    }

    private void lbPrevious_Click( object sender, EventArgs e )
    {
        this.PageIndex--;
        RaisePagingEvent( sender );
    }

    void lbAll_Click(object sender, EventArgs e)
    {
        this.PageIndex = 0;
        this.PageSize = 9999;
        RaisePagingEvent(sender);
    }

    void lbviewbypage_Click(object sender, EventArgs e)
    {
        this.PageIndex = 0;
        this.PageSize = 12;
        RaisePagingEvent(sender);
    }


    #endregion

    #region raise paging event

    private void RaisePagingEvent( object sender )
    {
              
        if ( this.PageIndexChanged != null )
        {
            
            this.PageIndexChanged( this, new DataGridPageChangedEventArgs( sender, this.PageIndex ) );
        }
    }

    #endregion

    #region set paging labels

    public void SetPagingLabels( int totalRecords )
    {
        int PageCount = Convert.ToInt32( Math.Ceiling( (double) totalRecords / this.PageSize ) );
        ArrayList Pages = new ArrayList( PageCount );
        for ( int page = 1; page <= PageCount; page++ )
        {
            Pages.Add( page );
        }
        this.rPages.DataSource = Pages;
        this.rPages.DataBind( );

        this.lbPrevious.Style.Add( "visibility", this.PageIndex == 0 ? "hidden" : "visible" );
        this.lbNext.Style.Add( "visibility", this.PageIndex == ( PageCount - 1 ) ? "hidden" : "visible" );
    }

    #endregion
    
}

now i want to add a viewall button to pager and use another constant string called "allgid", so it will display all the items in one page.

how can i do this and if i do this do i have to rewrite the pageIndex code.

Thanks and appreciate it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.