?
Solved

Gridview paging problem

Posted on 2009-02-19
9
Medium Priority
?
612 Views
Last Modified: 2012-05-06
I have a asp app that in the vb.net code-behind executes a sql statement and populates a dataset ( dsTepm1 ) . I then bind the dataset to the gridview as follows:

GridView1.DataSource = Dataset1
GridView1.DataBind()

The problem Im having is the paging. I am getting the error :
The GridView 'GridView1' fired event PageIndexChanging which wasn't handled

Any help would be appreciated
~steve
0
Comment
Question by:stephenz43
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:jjardine
ID: 23688442
Do you have an event handler for the PageIndexChanging event?    It would look something like      Public Sub PageIndexChanging(some parameters) Handles GridView1.PageIndexChanging
0
 

Author Comment

by:stephenz43
ID: 23688575
yes, but I haven't a clue on what code should be there. The sqlStatement returns 28 items. The grid paging is set on 10. When I click to the next page nothing happens.

0
 
LVL 14

Expert Comment

by:jjardine
ID: 23688589
can you post the code for that handler.  
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:stephenz43
ID: 23688618
I dont have any code in the handler....thats the problem. I suspect the handler should advance the read from the dataset by 10, but I dont know how to do it
0
 
LVL 14

Expert Comment

by:jjardine
ID: 23688629
0
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 23688887
Perhaps this sample will help:
Private Sub ItemsGridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles ItemsGridView.PageIndexChanging
    ItemsGridView_Refresh(e.NewPageIndex)
End Sub
Private Sub ItemsGridView_Refresh(ByVal pageIndex As Integer)
    ItemsGridView.PageIndex = pageIndex
    ItemsGridView_DataBind() ' method that calls the .DataBind method
End Sub
Private Sub ItemsGridView_DataBind()
		' Do something ...
		
		' Bind gridview
		ItemsGridView.DataBind
End Sub

Open in new window

0
 
LVL 5

Accepted Solution

by:
sumitkchawla earned 2000 total points
ID: 23690874
In the PageIndexChanging event handler you will get the current page index and the page size. Then you need to just bind the content of next page to the Grid.

for example:


You would also need to set the Virtual item count. This will be the exact count of the items you have in your datasource i.e. 28 in your case. This will enable Grid to show the required no of pages.

myHandler(pagesize, currentpageIndex){
int nextpage = currentpageIndex + 1;
int itemIndex = pagesize * nextpage;
List<MyItem> list;
for(count = itemindex; count<pagesize + itemindex ; count++)
{
  list.add(datasource.item[count]);
}
GridView.Datasource = list;

Open in new window

0
 

Author Comment

by:stephenz43
ID: 23698142
Hello
Sorry for the delay ...
I have the paging set to 20....when I click on the 2nd page...I get nothing. The gridview vanishes...

Steve
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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