Foros del Web » Programando para Internet » ASPX (.net) »

[SOLUCIONADO] Error al pintar celdas en GridView

Estas en el tema de Error al pintar celdas en GridView en el foro de ASPX (.net) en Foros del Web. HOla a todos, hoy se me ha presentado un problema. Quiero pintar mis celdas de color rojo cuando la cantidad faltante sea negativa, ya que ...
  #1 (permalink)  
Antiguo 05/06/2013, 09:36
Avatar de aid_val  
Fecha de Ingreso: mayo-2013
Ubicación: Guanajuato
Mensajes: 302
Antigüedad: 10 años, 11 meses
Puntos: 5
Pregunta Error al pintar celdas en GridView

HOla a todos, hoy se me ha presentado un problema.
Quiero pintar mis celdas de color rojo cuando la cantidad faltante sea negativa, ya que eso me indica que es un excedente. pero cuando quiero cargar la pagina me manda error

este es mi code behind

Protected Sub gv_cantidades_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv_cantidades.DataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cantidad As Single
cantidad = DataBinder.Eval(e.Row.DataItem, "cantidad_faltante")
If cantidad <= 5 Then
e.Row.BackColor = System.Drawing.Color.Red
e.Row.Font.Bold = True
End If
End If
End Sub

este es el error que me manda

No se puede convertir un objeto de tipo 'System.EventArgs' al tipo 'System.Web.UI.WebControls.GridViewRowEventArgs'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: No se puede convertir un objeto de tipo 'System.EventArgs' al tipo 'System.Web.UI.WebControls.GridViewRowEventArgs'.

Source Error:


[No relevant source lines]

Source File: C:\Users\Propietario\AppData\Local\Temp\Temporary ASP.NET Files\sipro\421e3836\3ed8522\App_Web_qn0tr4q0.0.vb Line: 0

Stack Trace:


[InvalidCastException: No se puede convertir un objeto de tipo 'System.EventArgs' al tipo 'System.Web.UI.WebControls.GridViewRowEventArgs'.]
formas_cargar_prefiniquito._Lambda$__1(Object a0, EventArgs a1) in C:\Users\Propietario\AppData\Local\Temp\Temporary ASP.NET Files\sipro\421e3836\3ed8522\App_Web_qn0tr4q0.0.vb :0
System.Web.UI.Control.OnDataBinding(EventArgs e) +91
System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable data) +54
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +33
System.Web.UI.WebControls.DataBoundControl.Perform Select() +143
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +74
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +66
System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls() +75
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
  #2 (permalink)  
Antiguo 05/06/2013, 10:05
Avatar de hylander2112  
Fecha de Ingreso: mayo-2013
Mensajes: 30
Antigüedad: 10 años, 10 meses
Puntos: 0
De acuerdo Respuesta: Error al pintar celdas en GridView

Hola aid_val ese problemilla está resuelto, te adjunto el url...

http://www.forosdelweb.com/f78/gridview-pintar-color-valores-celda-1053496/

slds.
  #3 (permalink)  
Antiguo 05/06/2013, 11:54
Avatar de aid_val  
Fecha de Ingreso: mayo-2013
Ubicación: Guanajuato
Mensajes: 302
Antigüedad: 10 años, 11 meses
Puntos: 5
Respuesta: Error al pintar celdas en GridView

mm el tema no me ayudo mucho porque mi problema es que en el evento me marca esto

código
No se puede convertir un objeto de tipo 'System.EventArgs' al tipo 'System.Web.UI.WebControls.GridViewRowEventArgs'.

y esporque cuando me crea el evento databound me lo hace asi e as System.eventArgs y yo lo cambio por System.Web.UI.webControls.GridviewRowEventArgs y me dice que no es posible hacer la conversión
  #4 (permalink)  
Antiguo 08/06/2013, 11:23
Avatar de aid_val  
Fecha de Ingreso: mayo-2013
Ubicación: Guanajuato
Mensajes: 302
Antigüedad: 10 años, 11 meses
Puntos: 5
Respuesta: Error al pintar celdas en GridView

Ya lo solucione y es de esta manera:
Protected Sub gv_cantidades_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_cantidades.RowDataBound
Try
If CDbl(e.Row.Cells(7).Text) < 0 Then
MsgBox("REVISAR VOLUMENES EXCEDENTES")
e.Row.Cells(7).BackColor = Drawing.Color.DarkRed
End If

Catch ex As Exception

End Try
End Sub
End Class
  #5 (permalink)  
Antiguo 20/06/2013, 10:49
Avatar de hylander2112  
Fecha de Ingreso: mayo-2013
Mensajes: 30
Antigüedad: 10 años, 10 meses
Puntos: 0
Información Respuesta: Error al pintar celdas en GridView

http://geekswithblogs.net/jaullo/archive/2011/05/06/colorear-celdas-y-filas-en-un-gridview.aspx
__________________
Slds.

Atte.

hylander2112

Etiquetas: asp, celdas, gridview, net, pintar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:01.