Gridview Pager customization issues.

Last post 11-20-2007 8:29 PM by villani. 9 replies.

Sort Posts:

  • Idea [Idea] Gridview Pager customization issues.

    05-09-2006, 11:54 AM
    • Member
      65 point Member
    • mvprakash
    • Member since 01-05-2004, 11:26 AM
    • Posts 14
     
    Hi
     
     I am creating custom Gridview with pager having option to pick page number
    from drop down list. Here is the code. The button images are assigned by
    the control user page. All buttons are are working fine.
    I am using PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;
    when i click the Last page button it throws the error shown below.
    
    
    The object datasource is set like this.
    
    "objER" runat="server" 
                EnablePaging="True" 
                SelectCountMethod="SelectCount"
                SelectMethod="GetAllECORequestPagable" 
                TypeName="Wix.Business.DataAccess.SqlServer.ECORequestDB"
                StartRowIndexParameterName ="startRow"
                MaximumRowsParameterName="maxRows"   >
        
    
    I do not know, what i am doing wrong. 
    
    
    
    --------The Error --------------------------
    Arithmetic operation resulted in an overflow. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.OverflowException: Arithmetic operation resulted in an overflow.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Stack Trace: 
    
    
    [OverflowException: Arithmetic operation resulted in an overflow.]
       System.Web.UI.WebControls.GridView.CreateDataSourceSelectArguments() +314
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +82
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
       System.Web.UI.WebControls.GridView.DataBind() +24
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +91
       System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +33
       System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +75
       System.Web.UI.Control.PreRenderRecursiveInternal() +148
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4412
    
    -- Here is the Custom pagegrid Code
    
    [ToolboxData("&lt;{0}:PageGridView runat=\"server\"&gt; </{0}:PageGridView>")  ]
        public class PageGridView : GridView
        {
    
            public PageGridView()
            {
                InitializeGridGomponent();
            }
    
            private void InitializeGridGomponent()
            {
                EnableViewState = false;
                AutoGenerateColumns = false;
    
                BorderWidth = 0;
                CellSpacing = 1;
                CellPadding = 0;
    
                // Paging and Sorting
                AllowPaging = true;
                AllowSorting = true;
                GridLines = GridLines.None;
    
                //Pager Setting
                PagerStyle.Width = Unit.Percentage(100);
                PagerStyle.HorizontalAlign = HorizontalAlign.Right;
                PagerStyle.VerticalAlign = VerticalAlign.Middle;
    
                PagerSettings.Position = PagerPosition.TopAndBottom;
                PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;
    
                PagerSettings.NextPageText = "Goto next page";
                PagerSettings.PreviousPageText = "Goto previous page";
                PagerSettings.FirstPageText = "Goto first page";
                PagerSettings.LastPageText = "Goto last page";
    
    
                
                RowCreated += new GridViewRowEventHandler(OnRowCreated);
         
            }
            
            void OnRowCreated(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.Pager)
                {
                    CustomizePageBar(e);
                }
            }
    
            private void CustomizePageBar(GridViewRowEventArgs e)
            {
    
                Table tblPager = new Table();
                tblPager.BorderWidth = 0;
                tblPager.CellPadding = 0;
                tblPager.CellSpacing = 0;
                tblPager.Width = Unit.Percentage(100);
                tblPager.Height = Unit.Pixel(20);
    
                //add a row for our pager contents
                tblPager.Rows.Add(new TableRow());
    
                //Spacer Cell
                TableCell tcelSpace = new TableCell();
                tcelSpace.Width = Unit.Pixel(360);
    
    
                //Page x of y Cell
                TableCell tcelXofY = new TableCell();
                tcelXofY.Width = Unit.Pixel(100);
    
                Label litXofY = new Label();
                litXofY.Text = "Page " + (this.PageIndex + 1) + " of " + this.PageCount;
                litXofY.Font.Bold = true;
                tcelXofY.Controls.Add(litXofY);
    
    
    
                //lable GoTo
                Label lblGoto = new Label();
                lblGoto.Text = "GoTo: ";
                lblGoto.ID = "lblGoTo";
                lblGoto.Font.Bold = true;
                lblGoto.Font.Size = this.PagerStyle.Font.Size;
    
                TableCell tcelGoto = new TableCell();
                tcelGoto.Width = Unit.Pixel(25);
                tcelGoto.Controls.Add(lblGoto);
    
    
                //Pick drop downlist
                TableCell tcelPickPage = new TableCell();
                tcelPickPage.Width = Unit.Pixel(25);
                //The dropdown list box
                DropDownList ddlPickPage = new DropDownList();
                ddlPickPage.ID = "ddlPick";
                ddlPickPage.AutoPostBack = true;
                ddlPickPage.EnableViewState = true;
                ddlPickPage.Font.Size = this.PagerStyle.Font.Size;
    
                for (int index = 1; index <= this.PageCount; index++)
                {
                    ddlPickPage.Items.Add(index.ToString());
                }
                ddlPickPage.SelectedIndex = this.PageIndex;
    
                //handle event for picklist
                ddlPickPage.SelectedIndexChanged += new EventHandler(OnPagePicked);
                tcelPickPage.Controls.Add(ddlPickPage);
    
                //The existing Nav controls
                TableCell tcelNav = new TableCell();
                tcelNav.Width = Unit.Pixel(150);
                
                //for move all existing controls
                foreach (Control ctrl in e.Row.Cells[0].Controls)
                {
                    tcelNav.Controls.Add(ctrl);
                }
    
                // add all cells to new pager
    
                tblPager.Rows[0].Cells.Add(tcelSpace);
                tblPager.Rows[0].Cells.Add(tcelXofY);
                tblPager.Rows[0].Cells.Add(tcelGoto);
                tblPager.Rows[0].Cells.Add(tcelPickPage);
                tblPager.Rows[0].Cells.Add(tcelNav);
    
    
                //replace grids pager with new
                e.Row.Cells[0].Controls.Add(tblPager);
    
                //EmbeddResources();
            }
    
            protected void OnPagePicked(object sender, EventArgs e)
            {
                DropDownList ddlPick = (DropDownList)sender;
                this.PageIndex = Convert.ToInt32(ddlPick.SelectedItem.Value) - 1;
                //Raise page index changed so user can rebind data
    
                GridViewPageEventArgs gvArgs = new GridViewPageEventArgs(Convert.ToInt32 (ddlPick.SelectedItem.Value) - 1);
                OnPageIndexChanging(gvArgs);
            }
    
    
     
        }
    }
     
  • Re: Gridview Pager customization issues.

    07-27-2006, 10:37 AM
    • Member
      433 point Member
    • DMAR78
    • Member since 07-26-2006, 10:44 PM
    • Posts 71

    Hi,

    Did you ever get a resolution to this?  I am having the exact same problem and can't figure out what I'm doing wrong.

     

    Thanks,

    D

    ** Remember to mark posts as the answer to help future users. **
    Visoft, Inc - Web Site | Blogs
  • Re: Gridview Pager customization issues.

    08-07-2006, 9:25 AM
    • Member
      65 point Member
    • mvprakash
    • Member since 01-05-2004, 11:26 AM
    • Posts 14
    No, i got no reply. I resorted to not use pager like this.
  • Re: Gridview Pager customization issues.

    08-18-2006, 12:02 PM
    • Contributor
      4,100 point Contributor
    • Scott Mitchell
    • Member since 06-15-2002, 8:41 PM
    • San Diego, CA
    • Posts 707
    • ASPInsiders
      TrustedFriends-MVPs
    Hello! I'm guessing that you've got EnableViewState="False" in your GridView? Set it to True, hopefully that does the trick.

    With custom paging, the page count value returned by the ObjectDataSource’s SelectCountMethod is stored in the GridView’s view state. Other GridView variables – the PageIndex, EditIndex, SelectedIndex, DataKeys collection, and so on – are stored in control state, which is persisted regardless of the value of the GridView’s EnableViewState property. Since the PageCount value is persisted across postbacks using view state, when using a paging interface that includes a link to take you to the last page, it is imperative that the GridView’s view state be enabled. (If your paging interface does not include a direct link to the last page, then you may disable view state.)

     

    Clicking the last page link causes a postback and instructs the GridView to update its PageIndex property. If the last page link is clicked, the GridView assigns its PageIndex property to a value one less than its PageCount property. With view state disabled, the PageCount value is lost across postbacks and the PageIndex is assigned the maximum integer value instead. Next, the GridView attempts to determine the starting row index by multiplying the PageSize and PageCount properties. This results in an OverflowException since the product exceeds the maximum allowed integer size.


    Happy Programming!
    Happy Programming!


    -- Scott Mitchell
    -- mitchell@4guysfromrolla.com
    -- http://scottonwriting.net/sowblog/
    -- http://www.4GuysFromRolla.com/ScottMitchell.shtml
  • Stick out tongue [:P] Re: Gridview Pager customization issues.

    08-18-2006, 9:07 PM
    • Member
      65 point Member
    • mvprakash
    • Member since 01-05-2004, 11:26 AM
    • Posts 14
    Thank you very much Mitchell. Yes that resolves the issue.
  • Re: Gridview Pager customization issues.

    09-11-2006, 5:02 PM
    • Member
      30 point Member
    • Reijnders
    • Member since 10-25-2004, 5:18 AM
    • Austria
    • Posts 6

    Hí, how I do integrate this class in my webappl.

    I have created the class in App_Code dir. In the aspx Page I made this <%@ Register TagPrefix="Custom" Namespace="BbackGridView"  %> but I got this error:

      Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Unknown server tag 'BbackGridView:PageGridView1'.

    Source Error:

    Line 198:              <td style='padding-top:0px; padding-left:19px; padding-bottom:20px'>
    Line 199:			
    Line 200:<BbackGridView:PageGridView1 DataKeyNames="BbackCode" ID="BBACK" AutoGenerateColumns="False" 
    Line 201:	OnRowCommand="BBACK_RowCommand" OnRowDataBound="BBACK_RowDataBound" DataKeyField="BbackCode"
    Line 202:	Width="501" GridLines="None" BackColor="#ffffff" CellSpacing="2" 

    This is the namespace:

     namespace BbackGridView
    {

    public class PageGridView1 : GridView
        {

            public PageGridView1()
            {
                InitializeGridGomponent();
            }

            private void InitializeGridGomponent()
            {
                EnableViewState = false;
                AutoGenerateColumns = false;

                BorderWidth = 0;
                CellSpacing = 1;
                CellPadding = 0;

                // Paging and Sorting
                AllowPaging = true;
                AllowSorting = true;
                GridLines = GridLines.None;

                //Pager Setting
                PagerStyle.Width = Unit.Percentage(100);
                PagerStyle.HorizontalAlign = HorizontalAlign.Right;
                PagerStyle.VerticalAlign = VerticalAlign.Middle;

                PagerSettings.Position = PagerPosition.TopAndBottom;
                PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;

                PagerSettings.NextPageText = "Goto next page";
                PagerSettings.PreviousPageText = "Goto previous page";
                PagerSettings.FirstPageText = "Goto first page";
                PagerSettings.LastPageText = "Goto last page";


               
                RowCreated += new GridViewRowEventHandler(OnRowCreated);
        
            }
           
            void OnRowCreated(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.Pager)
                {
                    CustomizePageBar(e);
                }
            }

            private void CustomizePageBar(GridViewRowEventArgs e)
            {

                Table tblPager = new Table();
                tblPager.BorderWidth = 0;
                tblPager.CellPadding = 0;
                tblPager.CellSpacing = 0;
                tblPager.Width = Unit.Percentage(100);
                tblPager.Height = Unit.Pixel(20);

                //add a row for our pager contents
                tblPager.Rows.Add(new TableRow());

                //Spacer Cell
                TableCell tcelSpace = new TableCell();
                tcelSpace.Width = Unit.Pixel(360);


                //Page x of y Cell
                TableCell tcelXofY = new TableCell();
                tcelXofY.Width = Unit.Pixel(100);

                Label litXofY = new Label();
                litXofY.Text = "Page " + (this.PageIndex + 1) + " of " + this.PageCount;
                litXofY.Font.Bold = true;
                tcelXofY.Controls.Add(litXofY);

     

                //lable GoTo
                Label lblGoto = new Label();
                lblGoto.Text = "GoTo: ";
                lblGoto.ID = "lblGoTo";
                lblGoto.Font.Bold = true;
                lblGoto.Font.Size = this.PagerStyle.Font.Size;

                TableCell tcelGoto = new TableCell();
                tcelGoto.Width = Unit.Pixel(25);
                tcelGoto.Controls.Add(lblGoto);


                //Pick drop downlist
                TableCell tcelPickPage = new TableCell();
                tcelPickPage.Width = Unit.Pixel(25);
                //The dropdown list box
                DropDownList ddlPickPage = new DropDownList();
                ddlPickPage.ID = "ddlPick";
                ddlPickPage.AutoPostBack = true;
                ddlPickPage.EnableViewState = true;
                ddlPickPage.Font.Size = this.PagerStyle.Font.Size;

                for (int index = 1; index <= this.PageCount; index++)
                {
                    ddlPickPage.Items.Add(index.ToString());
                }
                ddlPickPage.SelectedIndex = this.PageIndex;

                //handle event for picklist
                ddlPickPage.SelectedIndexChanged += new EventHandler(OnPagePicked);
                tcelPickPage.Controls.Add(ddlPickPage);

                //The existing Nav controls
                TableCell tcelNav = new TableCell();
                tcelNav.Width = Unit.Pixel(150);
               
                //for move all existing controls
                foreach (Control ctrl in e.Row.Cells[0].Controls)
                {
                    tcelNav.Controls.Add(ctrl);
                }

                // add all cells to new pager

                tblPager.Rows[0].Cells.Add(tcelSpace);
                tblPager.Rows[0].Cells.Add(tcelXofY);
                tblPager.Rows[0].Cells.Add(tcelGoto);
                tblPager.Rows[0].Cells.Add(tcelPickPage);
                tblPager.Rows[0].Cells.Add(tcelNav);


                //replace grids pager with new
                e.Row.Cells[0].Controls.Add(tblPager);

                //EmbeddResources();
            }

            protected void OnPagePicked(object sender, EventArgs e)
            {
                DropDownList ddlPick = (DropDownList)sender;
                this.PageIndex = Convert.ToInt32(ddlPick.SelectedItem.Value) - 1;
                //Raise page index changed so user can rebind data

                GridViewPageEventArgs gvArgs = new GridViewPageEventArgs(Convert.ToInt32 (ddlPick.SelectedItem.Value) - 1);
                OnPageIndexChanging(gvArgs);
            }


     
        }
    }

     

    Please help me to integrate this custom Gridviewpager in my aspx Page.

     Thanks a lot in advance

    Andreas

  • Re: Gridview Pager customization issues.

    09-22-2006, 8:18 AM
    • Member
      433 point Member
    • DMAR78
    • Member since 07-26-2006, 10:44 PM
    • Posts 71

    I don't see a runat=server tag.  Is it there for the control?

     Secondly, this error appears to be compile time since it's trying to parse the page, in which case this error usually appears because the control didn't compile correctly.  make sure that your custom grid is compiling before you register the control otherwise it won't be able to load on the target page.

    ** Remember to mark posts as the answer to help future users. **
    Visoft, Inc - Web Site | Blogs
  • Re: Gridview Pager customization issues.

    09-22-2006, 8:22 AM
    • Member
      433 point Member
    • DMAR78
    • Member since 07-26-2006, 10:44 PM
    • Posts 71

    Scott,

    This issue is long since dead but I did end up coming to the same conclusion by looking at reflector and seeing the insanely high value assigned to the PageCount when the ViewState was turned off in the gridview.  Nevertheless, we wanted our grids to work with or without viewstate, so the solution I put in place, albeit maybe a hack, was to NOT use the default "Last" command, and instead, set the commandArg of that particular pager button to PageCount - 1 once the grid is databound and knows how many pages are left.  This works like a charm and now we can use our custom pager with and without viewstate. Thanks for your reply though as it's helpful to many people that don't want to dig through reflector for half a day :)

    --Dave

    ** Remember to mark posts as the answer to help future users. **
    Visoft, Inc - Web Site | Blogs
  • Re: Gridview Pager customization issues.

    07-17-2007, 6:53 AM
    • Member
      55 point Member
    • rcaine
    • Member since 06-29-2006, 12:50 PM
    • England
    • Posts 52

     Hi,

     I have a problem related to the above...

     
    I'm trying to create my own custom pager and am programmatically adding Prev and Next linkbuttons to auto generated page number buttons. To get them to page I am setting the CommandName property to "Page" and the CommandArgument to "Prev" or "Next". They are not working though and on closer inspection I've noticed that the __doPostBack() javascript call does not include "Page$Prev" or "Page$Next" as the second parameter value. When commenting out my code and trying the built-in pager buttons, they do have these values. What am I doing wrong? I create my linkbutton pager controls like:

    LinkButton prev = new LinkButton();
    prev.Text = "&lt; Prev";
    prev.CommandName = "Page";
    prev.CommandArgument = "Prev";


     Thank you.

  • Re: Gridview Pager customization issues.

    11-20-2007, 8:29 PM
    • Member
      4 point Member
    • villani
    • Member since 11-20-2007, 8:25 PM
    • Posts 2

    rcaine:

     Hi,

     I have a problem related to the above...


    I'm trying to create my own custom pager and am programmatically adding Prev and Next linkbuttons to auto generated page number buttons. To get them to page I am setting the CommandName property to "Page" and the CommandArgument to "Prev" or "Next". They are not working though and on closer inspection I've noticed that the __doPostBack() javascript call does not include "Page$Prev" or "Page$Next" as the second parameter value. When commenting out my code and trying the built-in pager buttons, they do have these values. What am I doing wrong? I create my linkbutton pager controls like:

    LinkButton prev = new LinkButton();
    prev.Text = "&lt; Prev";
    prev.CommandName = "Page";
    prev.CommandArgument = "Prev";


     Thank you.

    Hi rcaine,

    Did you got a solution for your issue? I'm having the same problem.

    Thanks. 

Page 1 of 1 (10 items)