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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| Public Class GridViewTemplate
Implements ITemplate
Dim _templateType As ListItemType
Dim _columnName As String
Dim _TypeControl As eControl
Dim _Dts As DataSet
Public Enum eControl
textBox = 1
button = 2
label = 3
listbox = 4
gridview = 5
End Enum
Public Sub New(ByVal type As ListItemType, ByVal columnName As String, ByVal typeControl As eControl)
_templateType = type
_columnName = columnName
_TypeControl = typeControl
End Sub
Public Sub New(ByVal type As ListItemType, ByVal columnName As String, ByVal typeControl As eControl, ByVal dts As DataSet)
_templateType = type
_columnName = columnName
_TypeControl = typeControl
_Dts = dts
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Select Case _templateType
Case ListItemType.Item
Select Case _TypeControl
Case eControl.button
Dim btn As Button = New Button()
AddHandler btn.Click, AddressOf btn_Click
btn.CommandName = "EDIT"
container.Controls.Add(btn)
Case eControl.label
Dim lbl As Label = New Label()
lbl.BorderStyle = BorderStyle.None
AddHandler lbl.DataBinding, AddressOf lbl_DataBinding
container.Controls.Add(lbl)
Case eControl.textBox
Dim txt As TextBox = New TextBox()
AddHandler txt.DataBinding, AddressOf txt_DataBinding
txt.Columns = 3
'txt.ID = "txtQte"
txt.TextMode = TextBoxMode.SingleLine
txt.Width = 20
txt.Visible = True
container.Controls.Add(txt)
End Select
End Select
End Sub
Public Sub txt_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim txtData As TextBox = CType(sender, TextBox)
Dim container As GridViewRow = CType(txtData.NamingContainer, GridViewRow)
Dim dataValue As Object = DataBinder.Eval(container.DataItem, _columnName)
If Not IsNothing(dataValue) Then
txtData.Text = dataValue.ToString
End If
End Sub
Public Sub lbl_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim lblData As Label = CType(sender, Label)
Dim container As GridViewRow = CType(lblData.NamingContainer, GridViewRow)
Dim dataValue As Object = DataBinder.Eval(container.DataItem, _columnName)
If Not IsNothing(dataValue) Then
lblData.Text = dataValue.ToString
End If
End Sub
Public Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class |
Partager