1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
Class gvtmp
Implements ITemplate
Private templateType As DataControlRowType
Private columnName, columnType As String
Sub New(ByVal type As DataControlRowType, ByVal colname As String, ByVal coltype As String)
templateType = type
columnName = colname
columnType = coltype
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Select Case templateType
Case DataControlRowType.DataRow
Select Case columnType
Case "Edit"
Dim ddl As New DropDownList
AddHandler ddl.DataBinding, AddressOf EditDDL_DataBinding
container.Controls.Add(ddl)
Case "Item"
Dim l As New Label
AddHandler l.DataBinding, AddressOf Item_DataBinding
container.Controls.Add(l)
Case "Bloque"
Dim l As New Label
AddHandler l.DataBinding, AddressOf Bloque_DataBinding
container.Controls.Add(l)
End Select
Case DataControlRowType.Header
Dim lc As New Literal
lc.Text = "<b>" & columnType & "</b>"
container.Controls.Add(lc)
End Select
End Sub
Private Sub Item_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim l As Label = CType(sender, Label)
Dim row As GridViewRow = CType(l.NamingContainer, GridViewRow)
l.Text = DataBinder.Eval(row.DataItem, "Compo_Cph").ToString()
End Sub
Private Sub Bloque_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim l As Label = CType(sender, Label)
Dim row As GridViewRow = CType(l.NamingContainer, GridViewRow)
l.Text = DataBinder.Eval(row.DataItem, "Compo_Nom").ToString()
End Sub
Private Sub EditDDL_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)
With ddl
With .Items
.Add(New ListItem("A Gauche", "CphGauche"))
.Add(New ListItem("Au centre", "CphCentral"))
.Add(New ListItem("A Droite", "CphDroite"))
End With
.SelectedValue = DataBinder.Eval(row.DataItem, "Compo_Cph").ToString()
End With
End Sub
End Class |
Partager