| Public Class GridDetailTemplate |
| Implements ITemplate, System.Web.UI.IBindableTemplate |
| |
| Private controlID As String |
| Private clientID As String |
| Private type As ControlType |
| |
| 'This is the only public constructor. Should also accept the kind of control that needs to be created |
| Public Sub New(ByVal controlID As String, ByVal clientID As String, ByVal type As ControlType) |
| MyBase.New() |
| Me.controlID = controlID |
| Me.clientID = clientID |
| Me.type = type |
| End Sub |
| |
| |
| Public Function ExtractValues(ByVal container As Control) As Collections.Specialized.IOrderedDictionary Implements IBindableTemplate.ExtractValues |
| Dim returnDictionary As Collections.Specialized.OrderedDictionary = New Collections.Specialized.OrderedDictionary() |
| Select Case type |
| Case ControlType.Label |
| returnDictionary.Add(controlID, (DirectCast(((DirectCast(container, Telerik.Web.UI.GridDataItem)).FindControl(controlID)), Label)).Text) |
| |
| Case ControlType.PremiumTextBox |
| returnDictionary.Add(controlID, (DirectCast(((DirectCast(container, Telerik.Web.UI.GridDataItem)).FindControl(controlID)), TextBox)).Text) |
| End Select |
| Return returnDictionary |
| End Function |
| |
| Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn |
| 'create the control that we want |
| Dim control As New Control |
| |
| Select Case type |
| Case ControlType.PremiumTextBox |
| Dim txtBox As TextBox |
| txtBox = New TextBox |
| |
| 'attributes should be added in the item databound event to be consistent |
| txtBox.Attributes.Add("onblur", "return validateInput(this);") |
| 'txtBox.Attributes.Add("onchange", "return testInput(this);") |
| 'txtBox.Attributes.Add("onchange", "return addNumbers('" + txtBox.ClientID + "')") |
| 'should be in the textbox control |
| txtBox.MaxLength = 14 |
| txtBox.Width = Unit.Pixel(100) |
| txtBox.Style.Add("text-align", "right") |
| 'txtBox.ClientEvents.OnValueChanged = "calculateTtl" |
| |
| 'event handler to handle the databind event |
| control = txtBox |
| AddHandler control.DataBinding, AddressOf Me.TextBox1_DataBinding |
| End Select |
| |
| 'set the id to be an unique identifier for that row |
| control.ID = controlID |
| |
| 'add the control to the control collection |
| container.Controls.Add(control) |
| End Function |
| |
| Public Sub TextBox1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) |
| Dim textbox As TextBox = CType(sender, TextBox) |
| Dim grid As GridDataItem = CType(textbox.NamingContainer, GridDataItem) |
| Dim item1Value As String = DataBinder.Eval(grid.DataItem, controlID).ToString |
| CType(grid.FindControl(controlID), TextBox).Text = item1Value |
| End Sub |
| End Class |