Solved

PageIndexChanged and GridView - how to use

Posted on 2006-07-05
3
8,467 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
3 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 350 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 150 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now