Search code examples
asp.netdynamic-data

dynamic data - all option in paging


I'm developing a dynamic data web app. On list.aspx page it has GridViewPager control for paging, it option in drop down list as 10,20,.. rows in a page like that, but it does not an option show all rows in a page. How I can add "All" option in it?


Solution

  • In content folder Dynamic Data site lies the code for GridViewPager control.

    What I have done is I added "All" option in dropdown list with values 0, and in the code behind file in function DropDownListPageSize_SelectedIndexChanged I check if selected value is 0 then set AllowPaging = false else true.

    protected void DropDownListPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_gridView == null)
            {
                return;
            }
            DropDownList dropdownlistpagersize = (DropDownList)sender;
            int sz=Convert.ToInt32(dropdownlistpagersize.SelectedValue);
            //_gridView.PageSize = Convert.ToInt32(dropdownlistpagersize.SelectedValue);
            if (sz<=0)
            {
                _gridView.AllowPaging = false;
                //_gridView.DataBind();
                //return;
            }
            else
            {
                _gridView.AllowPaging = true;
                _gridView.PageSize = sz;
                _gridView.AllowPaging = true;
            }
            int pageindex = _gridView.PageIndex;
            _gridView.DataBind();
            if (_gridView.PageIndex != pageindex)
            {
                //if page index changed it means the previous page was not valid and was adjusted. Rebind to fill control with adjusted page
                _gridView.DataBind();
            }
        }