Mod Extensiones: Funciones para GridViews, hacer posible DataBind que incluya las columnas no visibles
Razonamiento: Las columnas marcadas como no visibles en un GridView no almacenan datos, antes de esto se tenía que poner visible la columna y volver a realizar de nuevo la consulta a la DB para recuperar el dato, agotando recursos innecesarios. - Se extiende DataBind() con el paramétro BindearCamposNoVisibles Ejemplo: Para Bindear un GridView que tambien contemple los campos ocultos, se manda a llamar Gv.DataBind(True)
This commit is contained in:
@@ -1628,6 +1628,66 @@ Namespace Extensiones
|
|||||||
Public Function FCRangeValidator(ByVal Row As GridViewRow, ByVal Control As String) As RangeValidator
|
Public Function FCRangeValidator(ByVal Row As GridViewRow, ByVal Control As String) As RangeValidator
|
||||||
Return DirectCast(Row.FindControl(Control), RangeValidator)
|
Return DirectCast(Row.FindControl(Control), RangeValidator)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
<Runtime.CompilerServices.Extension()>
|
||||||
|
Public Function GetColumn(ByVal gv As GridView, ByVal name As String) As Integer
|
||||||
|
Dim index As Integer = 0
|
||||||
|
Dim found As Boolean = False
|
||||||
|
|
||||||
|
For Each c As DataControlField In gv.Columns
|
||||||
|
|
||||||
|
If TypeOf c Is BoundField Then
|
||||||
|
Dim field As BoundField = CType(c, BoundField)
|
||||||
|
|
||||||
|
If name = field.DataField OrElse name = field.SortExpression OrElse name = field.HeaderText Then
|
||||||
|
found = True
|
||||||
|
Exit For
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
|
||||||
|
index += 1
|
||||||
|
Next
|
||||||
|
|
||||||
|
Return If(found, index, -1)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
<Runtime.CompilerServices.Extension()>
|
||||||
|
Public Function HiddenColumns(gv As GridView) As List(Of Integer)
|
||||||
|
Dim columns As New List(Of Integer)
|
||||||
|
|
||||||
|
For i As Integer = 0 To gv.Columns.Count - 1
|
||||||
|
If gv.Columns(i).Visible = False Then columns.Add(i)
|
||||||
|
Next
|
||||||
|
|
||||||
|
Return columns
|
||||||
|
End Function
|
||||||
|
|
||||||
|
<Runtime.CompilerServices.Extension()>
|
||||||
|
Public Sub ShowAllColumns(gv As GridView)
|
||||||
|
For i As Integer = 0 To gv.Columns.Count - 1
|
||||||
|
gv.Columns(i).Visible = True
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
<Runtime.CompilerServices.Extension()>
|
||||||
|
Public Sub HideColumns(gv As GridView, columns As List(Of Integer))
|
||||||
|
For Each i As Integer In columns
|
||||||
|
gv.Columns(i).Visible = False
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
<Runtime.CompilerServices.Extension()>
|
||||||
|
Public Sub DataBind(gv As GridView, BindearCamposNoVisibles As Boolean)
|
||||||
|
If BindearCamposNoVisibles Then
|
||||||
|
Dim NoVisibles As List(Of Integer) = gv.HiddenColumns()
|
||||||
|
gv.ShowAllColumns()
|
||||||
|
gv.DataBind()
|
||||||
|
gv.HideColumns(NoVisibles)
|
||||||
|
Else
|
||||||
|
gv.DataBind()
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
#End Region
|
#End Region
|
||||||
|
|
||||||
#Region "Excel PDF"
|
#Region "Excel PDF"
|
||||||
|
|||||||
Reference in New Issue
Block a user