Ver Mensaje Individual
  #8 (permalink)  
Antiguo 22/06/2008, 15:56
VAMP_01
 
Fecha de Ingreso: marzo-2002
Mensajes: 99
Antigüedad: 22 años, 1 mes
Puntos: 0
Respuesta: Ayuda con Gridview dinamico!!!


Ya despues de mucho leer....y ver ejemplos.....llegue a conseguir...el llenado de un gris en forma dinamica.....pero....aun no puedo hacer que dinamicamente de agregen tantos td como dias existan entre la fecha de inicio y la fecha de termino...
favor me pueden ayudar

lo q esta con rojo es lo que se me ocurrio, para hacer el loop para los td, ahora el problema es que el item5.text siempre esta vacio y necesti que se llene con el campo de la bd "dias", quew es el resultado de la resta de las fechas
la tabla de bd tiene 3 registros esta en access 2003, y se llama tabla1

la tabla tiene 4 columnas:
columnas :
a---------> tipo texto
b---------> tipo texto
c---------> date
d--------->date

y la consulta de donde extraigo los datos para llevarlos al webform es:

SELECT Tabla1.a, Tabla1.b, Tabla1.c, Tabla1.d, [d]-[c] AS dias
FROM Tabla1;

Aca esta el codigo:

<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="vb" Debug="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Public Class MyTemplate
Implements System.Web.UI.ITemplate

Dim templateType As ListItemType

Sub New(ByVal type As ListItemType)
templateType = type
End Sub

Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn

Dim ph As New PlaceHolder()
Dim item1 As New Label()
Dim item2 As New Label()
dim item3 as New Label()
dim item4 as New Label()
Dim item5 As New TextBox()
Dim item6 As New Label()
dim item7 as New Label()
dim item8 as New Label()
dim item9 as New Label()
dim item10 as New Label()
dim item11 as New Label()
dim item12 as New Label()
dim item13 as New Label()
dim item14 as New Label()
dim item15 as New Label()
dim item16 as New Label()
dim item17 as New Label()
dim item18 as New Label()
dim item19 as New Label()
dim item20 as New Label()
Dim i As Integer
Dim diaz As Integer
Dim clor As String = "#FF3399"



item1.ID = "item1"
item2.ID = "item2"
item3.ID = "item3"
item4.ID = "item4"
item5.ID = "item5"


Select Case (templateType)
Case ListItemType.Header
ph.Controls.Add(New LiteralControl("<table border=""0"">" & _
"<tr><td>IdMante</td><td>IdNeg</td><td>Fch Inicio</td><td>Fch Termino</td><td>Dias</td>"))
' & _"<td>DescripcionMante</td><td>HorasEstimadas</td><td>FchInicioEstimada</td><td>FchFinEstimada</td>" & _
' "<td>Dias</td><td>RPL</td><td>Estado CHP</td><td>FchFinReal</td><td>HorasReales</td><td>color</td>" & _
' "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"))
Case ListItemType.Item
ph.Controls.Add(New LiteralControl("<tr><td>"))
ph.Controls.Add(item1)
ph.Controls.Add(New LiteralControl("</td><td>"))
ph.Controls.Add(item2)
ph.Controls.Add(New LiteralControl("</td><td>"))
ph.Controls.Add(item3)
ph.Controls.Add(New LiteralControl("</td><td>"))
ph.Controls.Add(item4)
ph.Controls.Add(New LiteralControl("</td><td>"))
ph.Controls.Add(item5)
ph.Controls.Add(New LiteralControl("</td><td></td>"))
ph.Controls.Add(item6)


If item5.Text <> "" Then
diaz = item5.Text - 1
For i = 0 To diaz
ph.Controls.Add(New LiteralControl("<td bgcolor=" & clor & ">" & diaz + 1 & "</td>"))
ph.Controls.Add(item7)
Next (i)

End If

AddHandler ph.DataBinding, New EventHandler(AddressOf Item_DataBinding)
Case ListItemType.Footer
ph.Controls.Add(New LiteralControl("</table>"))
End Select
container.Controls.Add(ph)
End Sub
End Class

Shared Sub Item_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ph As PlaceHolder = CType(sender, PlaceHolder)
Dim ri As RepeaterItem = CType(ph.NamingContainer, RepeaterItem)
Dim item1Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "a"))
Dim item2Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "b"))
Dim item3Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "c"))
Dim item4Value As String = Convert.ToString(DataBinder.Eval(ri.DataItem, "d"))
Dim item5Value As Integer = Convert.ToString(DataBinder.Eval(ri.DataItem, "dias"))

CType(ph.FindControl("item1"), Label).Text = item1Value
CType(ph.FindControl("item2"), Label).Text = item2Value
CType(ph.FindControl("item3"), Label).Text = item3Value
CType(ph.FindControl("item4"), Label).Text = item4Value
CType(ph.FindControl("item5"), TextBox).Text = item5Value
End Sub

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

Dim Conn1 As New System.Data.OleDb.OleDbConnection(ConfigurationMan ager.ConnectionStrings("gpss").ConnectionString)

Dim sqlDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
Dim dsCategories1 As System.Data.DataSet
sqlDataAdapter1 = New OleDbDataAdapter("SELECT * FROM tabla_1_con ", Conn1)
dsCategories1 = New System.Data.DataSet()
Repeater1.HeaderTemplate = New MyTemplate(ListItemType.Header)
Repeater1.ItemTemplate = New MyTemplate(ListItemType.Item)
' Repeater1.AlternatingItemTemplate = New MyTemplate(ListItemType.AlternatingItem)
Repeater1.FooterTemplate = New MyTemplate(ListItemType.Footer)
sqlDataAdapter1.Fill(dsCategories1, "tabla_1_con")
Repeater1.DataSource = dsCategories1.Tables("tabla_1_con")
Repeater1.DataBind()

End Sub

</script>
<html >
<head id="Head1" runat="server">
<title>yo</title>
<style type="text/css">
<!--
.Estilo1 {
font-size: x-small;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="Estilo1">
<asp:Repeater id="Repeater1" runat="server"></asp:Repeater>
</div>
</form>
</body>
</html>

Favor me pueden ayudar a hacer que el td sea la diferencia que trae el campo dias

GRacias

:neuroti co