TemplateColumn with checkboxes

2 posts, 0 answers
  1. Rene
    Rene avatar
    5 posts
    Member since:
    Feb 2011

    Posted 20 May 2011 Link to this post

    Hi,

    I have tried to use your treelist with a template column for displaying a checkbox.

    I get the result that the template column is displayed but now I don't know how to get the check event for the checkboxes.

    I use the treelist as member of a usercontrol. There will be multiple instances of this usercontrol on the page.
    The content of the treeview will be rebuilt completely on Page_Load of the usercontrol.

    Don't know what's going wrong here. Hope you'll have a sample for fixing it.

    Sincerely

    René


    'on Page Load of the UserControl
      
                RadTreeList1.Style.Add(HtmlTextWriterStyle.Overflow, "auto")
      
      
                RadTreeList1.Width = mWidth
                RadTreeList1.Height = mHeight
      
                RadTreeList1.EditMode = TreeListEditMode.InPlace
                RadTreeList1.Enabled = True
      
                XmlDataSource1.DataFile = Path & "RowData.xml"
                RadTreeList1.Columns.Clear()
      
                Dim tmplt As New Web.UI.TemplateBuilder
      
      
                Dim selectColumn As New TreeListTemplateColumn
                selectColumn.DataField = "selected"
                selectColumn.EditItemTemplate = New CheckBoxTemplate("")
                selectColumn.ItemTemplate = New CheckBoxTemplate("")
      
                RadTreeList1.Columns.Add(selectColumn)
      
                Dim boundColumn As New TreeListBoundColumn
                boundColumn.DataField = "C2"
                boundColumn.UniqueName = "C2"
                boundColumn.HeaderText = "C2"
                RadTreeList1.Columns.Add(boundColumn)
      
      
        Private Sub RadTreeList1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.TreeListItemDataBoundEventArgs) Handles RadTreeList1.ItemDataBound 
            If TypeOf e.Item Is TreeListDataItem Then
                Dim dataItem As TreeListDataItem = e.Item
                Dim cb As Web.UI.WebControls.CheckBox
                cb = dataItem.FindControl("templateColumnCheckBox")
                AddHandler cb.CheckedChanged, AddressOf CheckBox1_CheckedChanged
                cb.Checked = True
            End If
        End Sub
      
        Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            'never get this event....
        End Sub
      
    Public Class CheckBoxTemplate
        Implements System.Web.UI.ITemplate
      
        Private CheckBox As System.Web.UI.WebControls.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 System.Web.UI.ITemplate.InstantiateIn
            CheckBox = New System.Web.UI.WebControls.CheckBox
            CheckBox.ID = "templateColumnCheckBox"
            CheckBox.AutoPostBack = True
            container.Controls.Add(CheckBox)
        End Sub
    End Class
  2. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 26 May 2011 Link to this post

    Hello Rene,

    When you want to create templates dynamically in RadTreeList you should create the entire treelist, along with the templates on the Page_Init event. Otherwise, the columns will not be able to persist their ViewState.

    Greetings,
    Tsvetina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top