?
Solved

PageIndexChanged and GridView - how to use

Posted on 2006-07-05
3
Medium Priority
?
8,494 Views
Last Modified: 2011-10-19
Hi, I am very new to web development, and would appreciate any advice given that helps me get going again.

Basically I just need to know how to use the pageindexchanging event on a gridview.

I have bound my gridview to a dataset (which in my example contains 18 records).

I am allowing paging on the gridview and set a limit of 5 results per pagesize, therefore I get 4 pages indicated on my gridview. However when I select the 2nd 3rd or 4th page I started getting an error about pageindexchanging not being handled.

So I created a sub routine to handle this event, but I do not know what to put in this Sub. At the moment the sub routine is blank but my gridview does not show when the page refreshes after selecting the 2nd 3rd or 4th page.

Any help is much appreciated.

Thanks
...Steve
0
Comment
Question by:swtiley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 1400 total points
ID: 17047351
Hi steve,
  have a look at this link to msdn  it talks about this event  http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pageindexchanged.aspx    and it basically shows this code...

Sub CustomersGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
     
    If Not IsPostBack Then
   
      ' Call a helper method to display the current page number
      ' when the page is first loaded.
      DisplayCurrentPage()
     
    End If
   
  End Sub

  Sub CustomersGridView_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
 
    ' Call a helper method to display the current page number
    ' when the user navigates to a different page.
    DisplayCurrentPage()
 
  End Sub

  Sub DisplayCurrentPage()
 
    ' Calculate the current page number.
    Dim currentPage As Integer = CustomersGridView.PageIndex + 1

    ' Display the current page number.
    Message.Text = "Page " & currentPage.ToString() & " of " & _
      CustomersGridView.PageCount.ToString() & "."
   
  End Sub

Hopefull this will help.
0
 
LVL 8

Assisted Solution

by:kaliyugkaarjun
kaliyugkaarjun earned 600 total points
ID: 17048905

Hi

The only thing u have to do is to increment the pageindex of ur grid on index change event..

 Private Sub urGridName_PageIndexChanged(ByVal source As Object, ByVal e As           System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles urGridName.PageIndexChanged
            urGridName.CurrentPageIndex = e.NewPageIndex
            BindTheData()
        End Sub

U can directly get this event in code behind by just selecting the grid event from the dropdpwnlist of methods

And just add these two lines in the method
   urGridName.CurrentPageIndex = e.NewPageIndex
and  
BindTheData()  //function in which u bind data to the grid

Hope this will help u

Just check this Link it might help u thouroughly with example
http://www.developerfusion.co.uk/show/5292/3/

Cheers!!!

0
 

Expert Comment

by:qtrmile69
ID: 23541169
since the last adviser gave me a lot of instruction...and it was quite a bit...i was wondering if you would be kind enough to assist me ...  enclosed are my two files for my aspx, and my cs..

as i was trying to explain to the last adviser, i am a little green with coding ..

would you be able to import the two files and edit according for me..???  I have re downloaded from my site, so it will be clean from where i originally started with him..
PlayerHistoryaspx.txt
PlayerHistoryaspxcs.txt
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question