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?
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 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.
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]
Dynamic DataGridView Pager
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
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
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
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
Dynamic DataAJAX History
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
defyant_2004
Member
55 Points
337 Posts
Retain "Number of Records" to display in GridView
May 13, 2009 03:41 PM|LINK
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?
defyant_2004
Member
55 Points
337 Posts
Re: Retain "Number of Records" to display in GridView
May 13, 2009 03:50 PM|LINK
I am using the default options for the GridView at the bottom.
Results per page:
defyant_2004
Member
55 Points
337 Posts
Re: Retain "Number of Records" to display in GridView
May 13, 2009 04:01 PM|LINK
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.
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Retain "Number of Records" to display in GridView
May 13, 2009 04:01 PM|LINK
This question relates to the Pager usercontrol from Dyanmic Data.
Dynamic Data
Always seeking an elegant solution.
defyant_2004
Member
55 Points
337 Posts
Re: Retain "Number of Records" to display in GridView
May 13, 2009 04:22 PM|LINK
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.
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Retain "Number of Records" to display in GridView
May 13, 2009 05:08 PM|LINK
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]
Dynamic Data GridView Pager
Always seeking an elegant solution.
defyant_2004
Member
55 Points
337 Posts
Re: Retain "Number of Records" to display in GridView
May 13, 2009 06:06 PM|LINK
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
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Retain "Number of Records" to display in GridView
May 14, 2009 10:32 AM|LINK
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.
Dynamic Data GridView Pager Size
Always seeking an elegant solution.
defyant_2004
Member
55 Points
337 Posts
Re: Retain "Number of Records" to display in GridView
May 14, 2009 03:06 PM|LINK
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.
sjnaughton
All-Star
25698 Points
5169 Posts
MVP
Re: Retain "Number of Records" to display in GridView
May 14, 2009 03:29 PM|LINK
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
Dynamic Data AJAX History
Always seeking an elegant solution.