Thursday, May 29, 2008

Gridview- Pagging

--------------Step-1----------
Add Folowing code in .aspx page in asp:gridview paging templete
------------------------------


EnableViewState="false" Text="Previous" CommandName="page" CommandArgument="prev">

 | 
EnableViewState="false" Text="Next" CommandName="page" CommandArgument="next">

  
Text=' SSLib.GetPosition(gvOrderList)'>



-----------------------------------------------
---------------------step-2-------------------
in back-side-aspx.vb page add following
----------------------------------------------
Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
Dim Paging As New GridViewPaging
Paging.GridViewPaging(gvClientList)
End Sub
-------------------------------------------------
---------------------step-3------------------
-------------------------------------------
add following 2-class in project------------
-------------------------------------------
Class1=
-------
Public Class GridViewPaging
Function GridViewPaging(ByVal GridViewId As GridView) As Boolean
Dim pagetoprow As GridViewRow = GridViewId.TopPagerRow
Dim pagerbotomrow As GridViewRow = GridViewId.BottomPagerRow
If Not (IsNothing(pagerbotomrow)) Then
If (GridViewId.PageIndex) = 0 Then
CType(GridViewId.BottomPagerRow.FindControl("lbPrevious"), LinkButton).Enabled = False
CType(GridViewId.BottomPagerRow.FindControl("lbPrevious"), LinkButton).CssClass = "DisableLink"
End If
If (GridViewId.PageIndex + 1) = GridViewId.PageCount Then
CType(GridViewId.BottomPagerRow.FindControl("lbNext"), LinkButton).Enabled = False
CType(GridViewId.BottomPagerRow.FindControl("lbNext"), LinkButton).CssClass = "DisableLink"
End If
End If
If Not (IsNothing(pagetoprow)) Then
If (GridViewId.PageIndex) = 0 Then
CType(GridViewId.TopPagerRow.FindControl("lbPrevious"), LinkButton).Enabled = False
CType(GridViewId.TopPagerRow.FindControl("lbPrevious"), LinkButton).CssClass = "DisableLink"
End If
If (GridViewId.PageIndex + 1) = GridViewId.PageCount Then
CType(GridViewId.TopPagerRow.FindControl("lbNext"), LinkButton).Enabled = False
CType(GridViewId.TopPagerRow.FindControl("lbNext"), LinkButton).CssClass = "DisableLink"
End If
End If
End Function
---------------------------------------
------class2-----------
--------------------------------------
Public Shared Function GetPosition(ByVal gv As GridView) As String
Return "( " & (gv.PageIndex + 1).ToString & " of " & gv.PageCount & " )"
End Function

Public Shared Function GetPosition(ByVal fv As FormView) As String
Return "( " & (fv.PageIndex + 1).ToString & " of " & fv.PageCount & " )"
End Function

Public Shared Function GetPageIndex(ByVal idx As Integer) As Integer
Return idx + (CInt(HttpContext.Current.Request("Pg")) * 12)
End Function

No comments: