Datagrid Paging Button Count
-
I have a datagrid that is bound to a dataset. I am having a problem getting the default paging to work properly. The page navigation buttons work for the first set of 10 pages. After selecting the "..." button to access the next set of 10 page buttons, when I select a new page button (for example, page 16), it takes me back to page 7. It is not indexing the page count & assuming that every page button count list is 0-10. Essentially, I can't view anything beyond page 10. Incidently, I tried setting the PagerStyle Mode="NextPrev" and I couldn't get past page 2 even though I kept selecting the ">" button. Here are my settings: AllowPaging=True; PageSize=10; PagerStyle Mode="Numeric Pages"; and PageButtonCount=10 Here is my code for the page index change event: Private Sub dgrdReport_PageIndexChanged(ByVal source As Object, _ ByVal e As System.Web.UI.Webcontrols.DataGridPageChangedEventArgs) _ Handles dgrdReport.PageIndexChanged Me.dgrdReport.CurrentPageIndex = e.NewPageIndex Me.dgrdReport.DataBind() End Sub Any suggestions on this issue would be appreciated. I have been struggling with this for a while now. Thanks.
-
I have a datagrid that is bound to a dataset. I am having a problem getting the default paging to work properly. The page navigation buttons work for the first set of 10 pages. After selecting the "..." button to access the next set of 10 page buttons, when I select a new page button (for example, page 16), it takes me back to page 7. It is not indexing the page count & assuming that every page button count list is 0-10. Essentially, I can't view anything beyond page 10. Incidently, I tried setting the PagerStyle Mode="NextPrev" and I couldn't get past page 2 even though I kept selecting the ">" button. Here are my settings: AllowPaging=True; PageSize=10; PagerStyle Mode="Numeric Pages"; and PageButtonCount=10 Here is my code for the page index change event: Private Sub dgrdReport_PageIndexChanged(ByVal source As Object, _ ByVal e As System.Web.UI.Webcontrols.DataGridPageChangedEventArgs) _ Handles dgrdReport.PageIndexChanged Me.dgrdReport.CurrentPageIndex = e.NewPageIndex Me.dgrdReport.DataBind() End Sub Any suggestions on this issue would be appreciated. I have been struggling with this for a while now. Thanks.
Hi, Try Declare a viewstate and have it as 0 initially and when the 10 button is clicked increment it by 10, 20 ,30 so as..... in Page index change this is in Page index change! Me.dgrdReport.CurrentPageIndex = e.NewPageIndex + (int)viewstate("Paging") Me.dgrdReport.DataBind() actually this wont happen it automatically works i dont know the reason but try this! Loving Code, R. Senthil Kumaran
-
Hi, Try Declare a viewstate and have it as 0 initially and when the 10 button is clicked increment it by 10, 20 ,30 so as..... in Page index change this is in Page index change! Me.dgrdReport.CurrentPageIndex = e.NewPageIndex + (int)viewstate("Paging") Me.dgrdReport.DataBind() actually this wont happen it automatically works i dont know the reason but try this! Loving Code, R. Senthil Kumaran
Thanks for your quick response. I did try something similar to this, but I could never get it to work properly. I will try your viewstate suggestion. I assume that I will also need to decrement the viewstate by 10, 20, 30 and so on whenever the back button is selected (that is, the "..." button that takes you to the previous set of 10 page buttons). One question, though ... where do I declare the viewstate = 0 initially? I can't have it in the page index change event. Thanks again.
-
Thanks for your quick response. I did try something similar to this, but I could never get it to work properly. I will try your viewstate suggestion. I assume that I will also need to decrement the viewstate by 10, 20, 30 and so on whenever the back button is selected (that is, the "..." button that takes you to the previous set of 10 page buttons). One question, though ... where do I declare the viewstate = 0 initially? I can't have it in the page index change event. Thanks again.
Yes ofcourse u need to decrement it too.. and the initial declaration of the viewstate u can have inside postback of the page load !! do reply me the result! Loving Code, R. Senthil Kumaran
-
Yes ofcourse u need to decrement it too.. and the initial declaration of the viewstate u can have inside postback of the page load !! do reply me the result! Loving Code, R. Senthil Kumaran
I was able to figure out what was going wrong. I was binding the datagrid every time the Page_Load event fired (at postback), instead of re-binding it on the PageIndexChanged event. I needed the following code in the Page_Load event: If Not Page.IsPostBack Then BindDataGrid() End If Also, I added the following code to the PageIndexChanged event: Dim dsReport As New DataSet Me.dgrdReport.CurrentPageIndex = e.NewPageIndex 'Re-bind the datagrid. dsReport = Session("dsReport") Me.dgrdReport.DataSource = dsReport.Tables("Report").DefaultView Me.dgrdReport.DataBind() Session("dsReport") = dsReport Thanks for your help. Sorry to take you on a tangent. But, it was helpful to discuss alternative methods for making this work.
-
I was able to figure out what was going wrong. I was binding the datagrid every time the Page_Load event fired (at postback), instead of re-binding it on the PageIndexChanged event. I needed the following code in the Page_Load event: If Not Page.IsPostBack Then BindDataGrid() End If Also, I added the following code to the PageIndexChanged event: Dim dsReport As New DataSet Me.dgrdReport.CurrentPageIndex = e.NewPageIndex 'Re-bind the datagrid. dsReport = Session("dsReport") Me.dgrdReport.DataSource = dsReport.Tables("Report").DefaultView Me.dgrdReport.DataBind() Session("dsReport") = dsReport Thanks for your help. Sorry to take you on a tangent. But, it was helpful to discuss alternative methods for making this work.
Ohh yes!! its correct u need to write that inside the Postback! and i have a question to u why do u need the dataset in session Never try to load a dataset or a datatable in session it seems urs is a report so it may have more data. more and more data in session makes load to your server which results in a performance issue and i dont think it i srequired also in this scenario!! consider this!!:) Loving Code, R. Senthil Kumaran