From 0383dabcb97413383e873de06db2aef7e459d632 Mon Sep 17 00:00:00 2001 From: MLopez Date: Tue, 10 Jan 2023 18:29:08 -0700 Subject: [PATCH] =?UTF-8?q?Mod=20Extensiones:=20Funciones=20para=20GridVie?= =?UTF-8?q?ws,=20hacer=20posible=20DataBind=20que=20incluya=20las=20column?= =?UTF-8?q?as=20no=20visibles=20Razonamiento:=20Las=20columnas=20marcadas?= =?UTF-8?q?=20como=20no=20visibles=20en=20un=20GridView=20no=20almacenan?= =?UTF-8?q?=20datos,=20antes=20de=20esto=20se=20ten=C3=ADa=20que=20poner?= =?UTF-8?q?=20visible=20la=20columna=20y=20volver=20a=20realizar=20de=20nu?= =?UTF-8?q?evo=20la=20consulta=20a=20la=20DB=20para=20recuperar=20el=20dat?= =?UTF-8?q?o,=20agotando=20recursos=20innecesarios.=20-=20Se=20extiende=20?= =?UTF-8?q?DataBind()=20con=20el=20param=C3=A9tro=20BindearCamposNoVisible?= =?UTF-8?q?s=20=20=20Ejemplo:=20Para=20Bindear=20un=20GridView=20que=20tam?= =?UTF-8?q?bien=20contemple=20los=20campos=20ocultos,=20se=20manda=20a=20l?= =?UTF-8?q?lamar=20Gv.DataBind(True)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App_Code/modExtensiones.vb | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/App_Code/modExtensiones.vb b/App_Code/modExtensiones.vb index ae5d47fc5..9685028a6 100644 --- a/App_Code/modExtensiones.vb +++ b/App_Code/modExtensiones.vb @@ -1628,6 +1628,66 @@ Namespace Extensiones Public Function FCRangeValidator(ByVal Row As GridViewRow, ByVal Control As String) As RangeValidator Return DirectCast(Row.FindControl(Control), RangeValidator) End Function + + + 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 + + + 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 + + + Public Sub ShowAllColumns(gv As GridView) + For i As Integer = 0 To gv.Columns.Count - 1 + gv.Columns(i).Visible = True + Next + End Sub + + + 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 + + + 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 #Region "Excel PDF"