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

ItemTemplate at Runtime

4 Answers 83 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 07 Oct 2008, 04:19 PM
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

 

4 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 08 Oct 2008, 01:35 PM
Any ideas please?
Mark
0
Yana
Telerik team
answered on 09 Oct 2008, 12:14 PM
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.
0
Mark
Top achievements
Rank 1
answered on 10 Oct 2008, 07:56 AM
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
0
Yana
Telerik team
answered on 13 Oct 2008, 11:42 AM
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.
Tags
TreeView
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Yana
Telerik team
Share this question
or