Solved

PageIndexChanged and GridView - how to use

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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