Solved

PageIndexChanged and GridView - how to use

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
MYSQL responding very slow 3 67
VB.Net creating Contact in Outlook 1 99
Set arraylist as datatable 2 29
vb.net dbnull syntax 1 59
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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