This is a migrated thread and some comments may be shown as answers.

Insert Checkbox control during itemdatabound event

1 Answer 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rupraj51
Top achievements
Rank 1
rupraj51 asked on 02 Aug 2012, 09:56 PM
Hi,

I am facing a problem while trying to insert checkbox control into the cell during the itemdatabound event. The grid is tied to the datatable which is created dynamically.

This is the code:

Protected Sub gvCompareAccessories_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gvCompareAccessories.ItemDataBound

        If (e.Item.ItemType = Telerik.Web.UI.GridItemType.Item Or e.Item.ItemType = Telerik.Web.UI.GridItemType.Item) Then
            'If TypeOf e.Item Is GridDataItem Then
            Dim dt As GridDataItem = DirectCast(e.Item, GridDataItem)

            'Dim imgbox As System.Web.UI.WebControls.Image = New System.Web.UI.WebControls.Image()

            If (e.Item.RowIndex = 2) Then
                Dim plcholder As PlaceHolder = New PlaceHolder()
                Dim chkbox As CheckBox = New CheckBox()
                For Each cellitem As GridTableCell In e.Item.Cells
                    chkbox.Text = "Remove"
                    plcholder.Controls.Add(chkbox)
                    cellitem.Controls.Add(plcholder)
                   
                Next
            End If

        End If
      
    End Sub

Here in the code i am trying to insert the checkbox into each cell of row index 2. But the checkbox appears only in the last column.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Aug 2012, 04:12 AM
Hi,

Please take look into the following code snippet to put the CheckBox in all cells in a row.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If (e.Item.ItemType = Telerik.Web.UI.GridItemType.Item Or e.Item.ItemType = Telerik.Web.UI.GridItemType.Item) Then
        Dim dt As GridDataItem = DirectCast(e.Item, GridDataItem)
        If (e.Item.RowIndex = 2) Then
            For Each cellitem As GridTableCell In e.Item.Cells
                Dim plcholder As New PlaceHolder()
                Dim chkbox As New CheckBox()
                chkbox.Text = "Remove"
                cellitem.Controls.Add(plcholder)
                plcholder.Controls.Add(chkbox)
            Next
        End If
    End If
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
rupraj51
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or