Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/02/2010, 09:12
iuranchita
 
Fecha de Ingreso: enero-2008
Ubicación: Santiago
Mensajes: 49
Antigüedad: 16 años, 10 meses
Puntos: 4
Respuesta: Paginar y ordenar un gridview

Hola, ocupé tu código, le hice unos cambios y me funcionó, aqui te lo mando todo de nuevo, por si aún lo necesitas.

Private Sub SortGridView(ByVal sortExpression As String, ByVal direction As String, ByVal dt As DataTable)

Dim dv As New Data.DataView(dt)

dv.Sort = sortExpression + " " + direction

Me.gvNub.DataSource = dv

Me.gvNub.DataBind()

End Sub


Public Property GridViewSortDirection() As SortDirection

Get

If ViewState("sortDirection") Is Nothing Then

ViewState("sortDirection") = SortDirection.Ascending

End If

Return DirectCast(ViewState("sortDirection"), SortDirection)

End Get

Set(ByVal value As SortDirection)

ViewState("sortDirection") = value

End Set

End Property

Protected Sub gvNub_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
Me.gvNub.PageIndex = e.NewPageIndex
Dim expresion As String = Session("sortexpresion").ToString()
Dim direccion As String = Session("sortdireccion").ToString()
If expresion = "" Or direccion = "" Then
Me.gvNub.DataSource = TraerDT()
Me.gvNub.DataBind()
Else
If direccion = "Ascending" Then
SortGridView(expresion, "ASC", odatos.load_nuv(2, 4, Contabilidad.Datos.Persistencia.ESPMostrarLoad.Por ID))
ElseIf direccion = "Descending" Then
SortGridView(expresion, "DESC", TraerDT())
End If

End If
End Sub

Protected Sub gvNub_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs)
Dim sortExpression As String = e.SortExpression

If GridViewSortDirection = SortDirection.Ascending Then

GridViewSortDirection = SortDirection.Descending

SortGridView(sortExpression, "DESC", odatos.load_nuv(2, 4, Contabilidad.Datos.Persistencia.ESPMostrarLoad.Por ID))

Else

GridViewSortDirection = SortDirection.Ascending

SortGridView(sortExpression, "ASC", odatos.load_nuv(2, 4, Contabilidad.Datos.Persistencia.ESPMostrarLoad.Por ID))

End If
Session("sortdireccion") = GridViewSortDirection
Session("sortexpresion") = e.SortExpression

End Sub


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
Session.Add("sortdireccion", "")
Session.Add("sortexpresion", "")
End If
CargarGrilla()
End Sub

Private Sub CargarGrilla()
Dim dt As New DataTable
Try
dt = TraerDT()
gvNub.DataSource = dt
gvNub.DataBind()

Catch ex As Exception

End Try
End Sub


Espero te sirva de algo, porque a mi me sirvió xD
saludos