Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:51:24+00:00 2026-06-11T14:51:24+00:00

i have a gridview that has paging enabled. i also have a dropdown on

  • 0

i have a gridview that has paging enabled. i also have a dropdown on the pager of the gridview where the user can select how many records per page they would like to retrieve. Once the dropdown is changed then an event is fired (shown below) to rerun the query with the updated results per page request. This works very well. I did however want to have a value “All” on the dropdown aswell and the method i used to impliment this is by disabling paging.

This all works brilliantly except for one issue. When the user selects “All” on the dropdown i would like to still show the pager once the gridview is updated. It doesnt show because i turned off paging but is there a way to show the pager again? See my code below for the event. (As you can see i renable the pager at the end but this has no effect)

thanks
damo

Code behind Event for Dropdown Change

void GridViewMainddl_SelectedIndexChanged(object sender, EventArgs e)
        {
            //changes page size
            if ((((DropDownList)sender).SelectedValue).ToString() == "All")
            {

                GridViewMain.AllowPaging = false;

            }
            else
            {
                GridViewMain.PageSize = int.Parse(((DropDownList)sender).SelectedValue);

            }



            //binds data source
            Result fAuditOverallStatusLatest = new Result(sConn);
            GridViewMain.DataSource = Result.getAuditOverallStatusLatest();            
            GridViewMain.PageIndex = 0;
            GridViewMain.DataBind();
            GridViewMain.AllowPaging = true;
            GridViewMain.BottomPagerRow.Visible = true;
            GridViewMain.TopPagerRow.Visible = true;
        }

DDL Code behind

protected void GridViewMain_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                DropDownList GridViewMainddl = new DropDownList();
                //adds variants of pager size
                GridViewMainddl.Items.Add("5");
                GridViewMainddl.Items.Add("10");
                GridViewMainddl.Items.Add("20");
                GridViewMainddl.Items.Add("50");
                GridViewMainddl.Items.Add("100");
                GridViewMainddl.Items.Add("200");
                GridViewMainddl.Items.Add("500");
                GridViewMainddl.Items.Add("All");
                GridViewMainddl.AutoPostBack = true;
                //selects item due to the GridView current page size
                ListItem li = GridViewMainddl.Items.FindByText(GridViewMain.PageSize.ToString());
                if (li != null)
                    GridViewMainddl.SelectedIndex = GridViewMainddl.Items.IndexOf(li);
                GridViewMainddl.SelectedIndexChanged += new EventHandler(GridViewMainddl_SelectedIndexChanged);
                //adds dropdownlist in the additional cell to the pager table
                Table pagerTable = e.Row.Cells[0].Controls[0] as Table;
                TableCell cell = new TableCell();
                cell.Style["padding-left"] = "15px";
                cell.Controls.Add(new LiteralControl("Page Size:"));
                cell.Controls.Add(GridViewMainddl);
                pagerTable.Rows[0].Cells.Add(cell);
                //add current Page of total page count
                TableCell cellPageNumber = new TableCell();
                cellPageNumber.Style["padding-left"] = "15px";
                cellPageNumber.Controls.Add(new LiteralControl("Page " + (GridViewMain.PageIndex + 1) + " of " + GridViewMain.PageCount));
                pagerTable.Rows[0].Cells.Add(cellPageNumber);

            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:51:26+00:00Added an answer on June 11, 2026 at 2:51 pm

    Put this in your Page_Init:

    GridViewMain.PreRender += new EventHandler(GridViewMain_PreRender);

    Then elsewhere in your Page class:

    void GridViewMain_PreRender(object sender, EventArgs e)
    {
        var pagerRow = (sender as GridView).BottomPagerRow;
        if (pagerRow != null)
        {
            pagerRow.Visible = true;
        }
    }
    

    Then for your drop down event:

    void GridViewMainddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        MyServices fServices = new FAServices(sConn);
        Result fAuditOverallStatusLatest = new Result(sConn);
        var data = Result.getAuditOverallStatusLatest();
    
        //changes page size
        if ((((DropDownList)sender).SelectedValue).ToString() == "All")
        {
            GridViewMain.PageSize = data.Count();
        }
        else
        {
            GridViewMain.PageSize = int.Parse(((DropDownList)sender).SelectedValue);
        }
    
        //binds data source
        GridViewMain.DataSource = data;            
        GridViewMain.PageIndex = 0;
        GridViewMain.DataBind();
        GridViewMain.AllowPaging = true;
    }
    

    In that PreRender event, you’ll have to duplicate that code for the top pager.

    Edit: To get All selected, make this change in GridViewMain_RowCreated:

    if (li != null)
    {
        GridViewMainddl.SelectedIndex = GridViewMainddl.Items.IndexOf(li);
    }
    else
    {
        GridViewMainddl.SelectedIndex = GridViewMainddl.Items.Count - 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control that has a gridview in it with paging. The
I have a GridView webcontrol that has paging and sorting enabled. I've bound the
I have a user control that contains a GridView. The GridView has both a
I have a Gridview that has filters that can fire off the emptydata template.
I have a gridview that has the ability to select rows. <asp:CommandField ShowSelectButton=true SelectImageUrl=~/Images/Icons/Cross.png
I have a gridview that is filtered with a dropdown box. The gridview has
I have a GridView that uses LinqDataSource. The GridView has default paging enable. I
I have a gridview customcontrol, for that paging event has defined in seperate class
I have a GridView that has 3 columns: FirstName, LastName and a TemplateField FullName
I have a gridview control that has on onclick event bound to every cell.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.