I have this code to dynmically create a checkbox template field and then access the settings of the checkbox:
SearchResultGrid.Columns.Clear()
Dim templateColumnName As String = "Delete"
Dim col2 As Telerik.Web.UI.GridTemplateColumn = New Telerik.Web.UI.GridTemplateColumn
col2.EditItemTemplate = New MyTemplate(templateColumnName)
col2.ItemTemplate = New MyTemplate(templateColumnName)
col2.HeaderText = templateColumnName
SearchResultGrid.Columns.Add(col2)
Private Class MyTemplate
Implements ITemplate
Protected boolValue As CheckBox
Private colname As String
Public Sub New(ByVal cName As String)
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
boolValue = New CheckBox()
boolValue.ID = "boolValue"
AddHandler boolValue.DataBinding, _
AddressOf boolValue_DataBinding
boolValue.Enabled = True
Dim table As New Table()
container.Controls.Add(table)
container.Controls.Add(boolValue)
End Sub
Sub boolValue_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim cBox As CheckBox = DirectCast(sender, CheckBox)
Dim container As Telerik.Web.UI.GridDataItem = DirectCast(cBox.NamingContainer, Telerik.Web.UI.GridDataItem)
'cBox.Checked = DirectCast((DirectCast(container.DataItem, DataRowView))("Bool"), Boolean)
End Sub
End Class
For Each item As Telerik.Web.UI.GridDataItem In SearchResultGrid.Items
Dim chk As CheckBox = item.FindControl("boolValue")
If chk.Checked Then
Dim j As Integer = 0
End If
Next
The problem is that in the For loop chk is getting set to Nothing. It's not finding the boolValue control.
How do I access the settings of boolValue for each row in the Grid ?
SearchResultGrid.Columns.Clear()
Dim templateColumnName As String = "Delete"
Dim col2 As Telerik.Web.UI.GridTemplateColumn = New Telerik.Web.UI.GridTemplateColumn
col2.EditItemTemplate = New MyTemplate(templateColumnName)
col2.ItemTemplate = New MyTemplate(templateColumnName)
col2.HeaderText = templateColumnName
SearchResultGrid.Columns.Add(col2)
Private Class MyTemplate
Implements ITemplate
Protected boolValue As CheckBox
Private colname As String
Public Sub New(ByVal cName As String)
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
boolValue = New CheckBox()
boolValue.ID = "boolValue"
AddHandler boolValue.DataBinding, _
AddressOf boolValue_DataBinding
boolValue.Enabled = True
Dim table As New Table()
container.Controls.Add(table)
container.Controls.Add(boolValue)
End Sub
Sub boolValue_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim cBox As CheckBox = DirectCast(sender, CheckBox)
Dim container As Telerik.Web.UI.GridDataItem = DirectCast(cBox.NamingContainer, Telerik.Web.UI.GridDataItem)
'cBox.Checked = DirectCast((DirectCast(container.DataItem, DataRowView))("Bool"), Boolean)
End Sub
End Class
For Each item As Telerik.Web.UI.GridDataItem In SearchResultGrid.Items
Dim chk As CheckBox = item.FindControl("boolValue")
If chk.Checked Then
Dim j As Integer = 0
End If
Next
The problem is that in the For loop chk is getting set to Nothing. It's not finding the boolValue control.
How do I access the settings of boolValue for each row in the Grid ?