Solved

PageIndexChanged and GridView - how to use

Posted on 2006-07-05
3
8,489 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 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 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