locked
Retain "Number of Records" to display in GridView RRS feed

  • Question

  • User-266149547 posted

    When users choose to set the "Number of Records" to display something other than the default number of 10 in the GridView and then perform an Insert, Update, or Delete, the "Number of Records" to display goes back to the default of 10.  Is this normal or should Dynamic Data be able to retain the users selection after performing a data action? 

    Wednesday, May 13, 2009 11:41 AM

Answers

All replies

  • User-266149547 posted

    I am using the default options for the GridView at the bottom.

    Results per page: <SELECT class=droplist id=ctl00_ContentPlaceHolder1_GridView1_ctl13_ctl00_DropDownListPageSize name=ctl00$ContentPlaceHolder1$GridView1$ctl13$ctl00$DropDownListPageSize> <OPTION value=5>5</OPTION> <OPTION value=10 selected>10</OPTION> <OPTION value=15>15</OPTION> <OPTION value=20>20</OPTION></SELECT>

    Wednesday, May 13, 2009 11:50 AM
  • User-266149547 posted

    Down at the bottom of the GridView there is a dropdownlist "Results Per Page".  It defaults to 10.   If a user chooses 20, for example, and then decides to perform and action a selected record,  the "Results Per Page" goes back to 10, not the users prefered 20.

    It also sends the user back to the first page.

    Wednesday, May 13, 2009 12:01 PM
  • User-330204900 posted

    This question relates to the Pager usercontrol from Dyanmic Data.

    Wednesday, May 13, 2009 12:01 PM
  • User-266149547 posted

    It seems it should be able to retain this value for the user.  Do you know if there are plans to address it?  It seems small but a few users have complained about it.  I ended writing some code to store in the session variable as a temporary quick fix.

    Wednesday, May 13, 2009 12:22 PM
  • User-330204900 posted

    It seems it should be able to retain this value for the user.

    Yes, I think you are right when you change it is should stay changes may be add a session variable that gets changed when it is changed in the dropdown list.

    I'll work something up [:D]

    Wednesday, May 13, 2009 1:08 PM
  • User-266149547 posted

     

    The dropdownlist is the default dropdownlist in the GridView that is used by the List.aspx page.  I am adding the code I used to correct this issue.  It seems it would be nice if future versions of Dynamic Data would handle this.   My code below also attempts to handle the Current Page Index.

    I appreciate any comments about the following code if there is better way.

    List.aspx.vb page

         Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

           If Session("NumberOfRecordsDisplayed") Is Nothing Then
                Session("NumberOfRecordsDisplayed") = 10
                GridView1.PageSize = Session("NumberOfRecordsDisplayed")
            Else
                GridView1.PageSize = Session("NumberOfRecordsDisplayed")
            End If

            If Session("CurrentPageIndexNumber") Is Nothing Then
                Session("CurrentPageIndexNumber") = 0
                GridView1.PageIndex = Session("CurrentPageIndexNumber")
            Else
                GridView1.PageIndex = Session("CurrentPageIndexNumber")
            End If

            Label1.Text = Session("NumberOfRecordsDisplayed")
            Label2.Text = Session("CurrentPageIndexNumber")

            table = GridDataSource.GetTable
            Title = table.DisplayName
            GridDataSource.Include = table.ForeignKeyColumnsNames
            InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert)
            ' Disable various options if the table is readonly
            If table.IsReadOnly Then
                GridView1.Columns(0).Visible = False
                InsertHyperLink.Visible = False
            End If
        End Sub

     

        Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
            Session("CurrentPageIndexNumber") = GridView1.PageIndex
        End Sub


    --------------------
    Pager.ascx.vb

        Protected Sub DropDownListPageSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownListPageSize.SelectedIndexChanged
            If (_gridView Is Nothing) Then
                Return
            End If
            Dim dropdownlistpagersize As DropDownList = CType(sender, DropDownList)

            'Modified the following two lines of code to update the session variable to the number of records to be displayed
            Session("NumberOfRecordsDisplayed") = Convert.ToInt32(dropdownlistpagersize.SelectedValue)
            _gridView.PageSize = Session("NumberOfRecordsDisplayed")
            'Added the following line of code to update the session variable to the new page index
            Session("CurrentPageIndexNumber") = _gridView.PageIndex
           
            Dim pageindex As Integer = _gridView.PageIndex
            _gridView.DataBind()
            If (_gridView.PageIndex <> pageindex) Then
                'if page index changed it means the previous page was not valid and was adjusted. Rebind to fill control with adjusted page
                _gridView.DataBind()
            End If
        End Sub

    Wednesday, May 13, 2009 2:06 PM
  • User-330204900 posted

    I just did a post on this, thought I'd post a link here [:D] Retaining Pager Size in Dynamic Data GridViewPager and I've included a version that supports different pager sizes per table.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 14, 2009 6:32 AM
  • User-266149547 posted

    I appreciate your assistance and fix for this issue.  I am in the process of improving my original code with your project.

    It seems this fix could be expanded to the GridView Index not being retained issue and Sort Columns not being retained issue.

    Thursday, May 14, 2009 11:06 AM
  • User-330204900 posted

    It may be better to fix the Page index using AJAX History instead of session as there are too many ways of returning to the list page to be messing around with Session variables. see Managing Browser History on the Client with ASP.NET AJAX and the ASP.NET 3.5 Extensions Preview by Mike Ormond it helped me with my AJAX History in a Dynamic Data Website

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 14, 2009 11:29 AM
  • User-266149547 posted

    Thats a good point.  I have all this coded in a custom page in the CustomPages directory.  Only one page is affected.   It would not work with the standard pages in the PageTemplates directory when switching from one table to another.  Neither would sorted columns when switching tables, because the fields would not be the same.  I developed all my code for the one custom page.  Thanks again.

    Thursday, May 14, 2009 12:46 PM
  • User-330204900 posted

    And finally the Ajax History bits for Page Index [:D] (sumg smile) Remembering Page Index when returning to a List Page

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 15, 2009 11:13 AM