We are creating the radgrid dynamically in code behind with one bound column and other template columns.
We are not able to find checkbox control in gridDataItem using gridDataItem.FindControl method although text of bound column is available.
Please provide solution for the same.
Code:
The folowing method is called on page load:
----------------------------------------------------------------------------------------------------------------------
Private Function UpdateGridActionColumns() As GridColumnCollection
Dim actionCollection As GridColumnCollection
Dim dsActions As New DataSet
Dim dtActions As New DataTable
Try
actionCollection = New GridColumnCollection(RadGrid1_Functions.MasterTableView)
dsActions = Me._appObject.GetAllActions().ConvertToDataSet()
RadGrid1_Functions.MasterTableView.Columns.Clear()
Dim boundColumn As New GridBoundColumn
boundColumn.DataField = "APP_FUNCTION_ID"
boundColumn.UniqueName = "SEC_FUNCTION_ID"
boundColumn.HeaderText = "Function"
RadGrid1_Functions.MasterTableView.Columns.Add(boundColumn)
If dsActions.Tables.Count > 0 Then
dtActions = dsActions.Tables(0)
For ctr As Integer = 0 To dtActions.Rows.Count - 1
Dim templateColumnID As String = dtActions.Rows(ctr)("Action_Id")
Dim templateColumn As GridTemplateColumn = New GridTemplateColumn
templateColumn.ItemTemplate = New MyTemplate(templateColumnID)
templateColumn.UniqueName = templateColumnID
templateColumn.DataField = "Action_Id"
templateColumn.HeaderText = dtActions.Rows(ctr)("Action_Name")
RadGrid1_Functions.MasterTableView.Columns.Add(templateColumn)
Next
End If
Return actionCollection
Catch ex As Exception
Return Nothing
End Try
End Function
----------------------------------------------------------------------------------------------------------------------
Template column class is:
Private Class MyTemplate
Implements ITemplate
Protected chkTempColumn As CheckBox
Private colname As String
Public Sub New(ByVal cName As String)
MyBase.New()
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
chkTempColumn = New CheckBox
chkTempColumn.ID = "chk" & colname
AddHandler chkTempColumn.DataBinding, AddressOf Me.chkTempColumn_DataBinding
Dim table As Table = New Table
Dim row As TableRow = New TableRow
Dim cell As TableCell = New TableCell
table.BorderWidth = 0
row.BorderWidth = 0
cell.BorderWidth = 0
row.Cells.Add(cell)
table.Rows.Add(row)
cell.Controls.Add(chkTempColumn)
container.Controls.Add(table)
'container.Controls.Add(boolValue)
End Sub
Private Sub chkTempColumn_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim cBox As CheckBox = CType(sender, CheckBox)
Dim container As GridDataItem = CType(cBox.NamingContainer, GridDataItem)
Dim dr As DataRow = CType(container.DataItem, DataRowView).Row
'cBox.Checked = CType(CType(container.DataItem, DataRowView)("Bool"), Boolean)
Select Case Integer.Parse(dr(colname))
Case 0
cBox.Checked = False
Case 1
cBox.Checked = True
Case -1
cBox.Checked = False
cBox.Enabled = False
End Select
End Sub
End Class
----------------------------------------------------------------------------------------------------------------------
Please provide the solution for same.
Please mark a copy of solution to:
chetan.mehta@cognizant.com
Regards
Chetan
Frameworks team, marketRx (A Cognizant company)
P.S: We have purchased Telerik UI suite but raising ticket here since the subscription has expired.
We are not able to find checkbox control in gridDataItem using gridDataItem.FindControl method although text of bound column is available.
Please provide solution for the same.
Code:
The folowing method is called on page load:
----------------------------------------------------------------------------------------------------------------------
Private Function UpdateGridActionColumns() As GridColumnCollection
Dim actionCollection As GridColumnCollection
Dim dsActions As New DataSet
Dim dtActions As New DataTable
Try
actionCollection = New GridColumnCollection(RadGrid1_Functions.MasterTableView)
dsActions = Me._appObject.GetAllActions().ConvertToDataSet()
RadGrid1_Functions.MasterTableView.Columns.Clear()
Dim boundColumn As New GridBoundColumn
boundColumn.DataField = "APP_FUNCTION_ID"
boundColumn.UniqueName = "SEC_FUNCTION_ID"
boundColumn.HeaderText = "Function"
RadGrid1_Functions.MasterTableView.Columns.Add(boundColumn)
If dsActions.Tables.Count > 0 Then
dtActions = dsActions.Tables(0)
For ctr As Integer = 0 To dtActions.Rows.Count - 1
Dim templateColumnID As String = dtActions.Rows(ctr)("Action_Id")
Dim templateColumn As GridTemplateColumn = New GridTemplateColumn
templateColumn.ItemTemplate = New MyTemplate(templateColumnID)
templateColumn.UniqueName = templateColumnID
templateColumn.DataField = "Action_Id"
templateColumn.HeaderText = dtActions.Rows(ctr)("Action_Name")
RadGrid1_Functions.MasterTableView.Columns.Add(templateColumn)
Next
End If
Return actionCollection
Catch ex As Exception
Return Nothing
End Try
End Function
----------------------------------------------------------------------------------------------------------------------
Template column class is:
Private Class MyTemplate
Implements ITemplate
Protected chkTempColumn As CheckBox
Private colname As String
Public Sub New(ByVal cName As String)
MyBase.New()
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
chkTempColumn = New CheckBox
chkTempColumn.ID = "chk" & colname
AddHandler chkTempColumn.DataBinding, AddressOf Me.chkTempColumn_DataBinding
Dim table As Table = New Table
Dim row As TableRow = New TableRow
Dim cell As TableCell = New TableCell
table.BorderWidth = 0
row.BorderWidth = 0
cell.BorderWidth = 0
row.Cells.Add(cell)
table.Rows.Add(row)
cell.Controls.Add(chkTempColumn)
container.Controls.Add(table)
'container.Controls.Add(boolValue)
End Sub
Private Sub chkTempColumn_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim cBox As CheckBox = CType(sender, CheckBox)
Dim container As GridDataItem = CType(cBox.NamingContainer, GridDataItem)
Dim dr As DataRow = CType(container.DataItem, DataRowView).Row
'cBox.Checked = CType(CType(container.DataItem, DataRowView)("Bool"), Boolean)
Select Case Integer.Parse(dr(colname))
Case 0
cBox.Checked = False
Case 1
cBox.Checked = True
Case -1
cBox.Checked = False
cBox.Enabled = False
End Select
End Sub
End Class
----------------------------------------------------------------------------------------------------------------------
Please provide the solution for same.
Please mark a copy of solution to:
chetan.mehta@cognizant.com
Regards
Chetan
Frameworks team, marketRx (A Cognizant company)
P.S: We have purchased Telerik UI suite but raising ticket here since the subscription has expired.