.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Paging with grid view in vb.net

Posted By: Naresh     Posted Date: May 28, 2010    Points:2   Category :VB.Net
Hi,

I need procedur and coading for custom paging for grid view in vb.net.
I have four buttons for first,previous,next and last page to view

Thanks in Advance.




Naresh

Responses
Author: Lalij Mer             
Posted Date: May 28, 2010     Points: 5   

Try this Code Sample
Paging for First Button:

Protected Sub btnfirst_Click(sender As Object, e As EventArgs)

gridview1.PageIndex = 0
End Sub


Paging for Next Button:


Protected Sub btnnext_Click(sender As Object, e As EventArgs)

Dim i As Integer = gridview1.PageIndex + 1

If i <= gridview1.PageCount Then

gridview1.PageIndex = i
End If
End Sub


Paging for Previous Button:

Protected Sub btnprevious_Click(sender As Object, e As EventArgs)

Dim i As Integer = gridview1.PageCount

If gridview1.PageIndex > 0 Then

gridview1.PageIndex = gridview1.PageIndex - 1
End If

End Sub


Paging for Last Button:


Protected Sub btnlast_Click(sender As Object, e As EventArgs)
gridview1.PageIndex = gridview1.PageCount
End Sub

Here Complete Code Sample

Imports System

Imports System.Data

Imports System.Configuration

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls



Public Partial Class _Default
Inherits System.Web.UI.Page


Protected Sub Page_Load(sender As Object, e As EventArgs)




btnfirst.Enabled = False

btnprevious.Enabled = False



End Sub

Protected Sub btnnext_Click(sender As Object, e As EventArgs)


Dim i As Integer = gridview1.PageIndex + 1

If i <= gridview1.PageCount Then


gridview1.PageIndex = i

btnlast.Enabled = True

btnprevious.Enabled = True


btnfirst.Enabled = True
End If

If gridview1.PageCount - 1 = gridview1.PageIndex Then


btnnext.Enabled = False


btnlast.Enabled = False
End If

End Sub

Protected Sub btnprevious_Click(sender As Object, e As EventArgs)


Dim i As Integer = gridview1.PageCount

If gridview1.PageIndex > 0 Then

gridview1.PageIndex = gridview1.PageIndex - 1


btnlast.Enabled = True
End If


If gridview1.PageIndex = 0 Then

btnfirst.Enabled = False
End If

If gridview1.PageCount - 1 = gridview1.PageIndex + 1 Then


btnnext.Enabled = True
End If

If gridview1.PageIndex = 0 Then

btnprevious.Enabled = False
End If

End Sub

Protected Sub btnlast_Click(sender As Object, e As EventArgs)

gridview1.PageIndex = gridview1.PageCount

btnlast.Enabled = False

btnfirst.Enabled = True

End Sub

Protected Sub btnfirst_Click(sender As Object, e As EventArgs)


gridview1.PageIndex = 0

btnfirst.Enabled = False

btnprevious.Enabled = False

btnlast.Enabled = True

btnnext.Enabled = True



End Sub

End Class





Please Check my answer if you help....
Thank You...

Lalit.
Author: Akhil Raj       [Moderator]      
Posted Date: May 28, 2010     Points: 5   

hi naresh,

You can use pagertemplate to customize the name and buttons according to your wish.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend