ItemTemplate at Runtime

5 posts, 0 answers
  1. Mark
    Mark avatar
    132 posts
    Member since:
    Feb 2008

    Posted 07 Oct 2008 Link to this post

    Hi,
    i have successfully added a label to the node template and populated this with a database field. (using Adding and Editing Templates at Runtime help).

    I am trying to add more labels, which i can do, however...
    How do i assign another fieldname to this label ?
    ie; label1 shows EmailSubject, label2 needs to show EmailFrom, etc..

    Thanks
    Mark

    Heres what i have working so far...

    trvEmails.DataSource = myDataTable

    trvEmails.DataTextField =

    "EmailSubject"

     

    trvEmails.DataBind()


     

    Public Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn

     

     

    Dim lbl As New Label()

     

    lbl.ID =

    "Label"

     

     

    AddHandler lbl.DataBinding, AddressOf lbl_DataBinding

     

     

    Dim lbl2 As New Label()

     

    lbl2.ID =

    "Label2"

     

     

    AddHandler lbl2.DataBinding, AddressOf lbl2_DataBinding

     

    container.Controls.Add(lbl)

    container.Controls.Add(lbl2)

     

    End Sub

     

     

    Private Sub lbl_DataBinding(ByVal sender As Object, ByVal e As EventArgs)

     

     

    Try

     

     

    Dim target As Label = sender

     

     

    Dim node As RadTreeNode = DirectCast(target.BindingContainer, RadTreeNode)

     

     

    Dim itemText As String = DirectCast(DataBinder.Eval(node, "Text"), String)

     

    target.Text = itemText

     

    Catch ex As Exception

     

     

    End Try

     

     

    End Sub

     

     

    Private Sub lbl2_DataBinding(ByVal sender As Object, ByVal e As EventArgs)

     

     

    Try

     

     

    Dim target As Label = sender

     

     

    Dim node As RadTreeNode = DirectCast(target.BindingContainer, RadTreeNode)

     

     

    Dim itemText As String = DirectCast(DataBinder.Eval(node, "Text"), String)

     

    target.Text = itemText

     

    Catch ex As Exception

     

     

    End Try

     

     

    End Sub

     

  2. Mark
    Mark avatar
    132 posts
    Member since:
    Feb 2008

    Posted 08 Oct 2008 Link to this post

    Any ideas please?
    Mark
  3. Yana
    Admin
    Yana avatar
    4813 posts

    Posted 09 Oct 2008 Link to this post

    Hello Mark,

    I suggest you use Custom Attributes to pass additional values to the nodes of RadTreeView. This help article shows how you can these values from the database.

    I hope this helps.

    Regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Mark
    Mark avatar
    132 posts
    Member since:
    Feb 2008

    Posted 10 Oct 2008 Link to this post

    Hi,
    Not really what i meant (Custom Attributes).

    All i want to do is display a node with multiple lines of text (ie; labels - above and below each other ).
    For example, the top line of the node text will be black and bold. the 2nd line will be blue underlined..etc...

    Plus, these labels text need to be drawn from a database.

    Thanks
    Mark
  5. Yana
    Admin
    Yana avatar
    4813 posts

    Posted 13 Oct 2008 Link to this post

    Hi Mark,

    Please check the attached sample project which shows the needed approach, you just have to style the labels in the node template of RadTreeView. 

    I hope it helps.

    All the best,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top