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

[Solved] Rendering TreeViewItem using cssClass

1 Answer 33 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Klaus
Top achievements
Rank 1
Klaus asked on 15 May 2011, 06:38 AM

The following code does not render my TreeView child nodes as expected.  (Sorry,cannot figure out how to format code snippet).

 

 

Html.Telerik().TreeView()

 

.Name(

"TreeView")

 

 

.BindTo(Model

as IEnumerable, (mappings) =>

 

 

{

 

mappings.For<

ArticleSummary>(binding => binding

 

 

.ItemDataBound((item, category) =>

 

{

 

item.Text = category.Abstract;

 

})

 

.Children(category => category.Children));

 

mappings.For<

ArticleSummary>(binding => binding

 

 

.ItemDataBound((item, article) =>

 

{

 

item.Content = () =>

 

{

 

%>

 

 

 

 

<div class="img-box3">

 

 

 

 

 

 

<%

if (article.ContainsValidThumbNail())

 

 

{ %>

 

 

<img src='<%=Url.Action("GetImageForArticleId", "Resources", new { id = article.Id })%>' alt=""/>

 

 

<%}%>

 

<%

=article.Abstract%>

 

 

<%

if (article.ContainsMainText)

 

 

{ %>

 

 

<a> <%= Html.ActionLink("Details", "Details", "News", new { newsId = article.Id }, null)%></a>

 

 

<% } %>

 

 

</div>

 

 

 

 

 

 

<%

 

};

 

 

 

}));

 

}).Render();

 

%>

All I see it articl.Abstract rendered for each node.  I do not see the image and ActionLink. Please note that all code within item.Content() works well outside of the tree view.  Is this the proper way of creating each node using a cssClass? 

TIA.

1 Answer, 1 is accepted

Sort by
0
Klaus
Top achievements
Rank 1
answered on 16 May 2011, 05:15 AM
Problem mostly solved after upgrading to MVC3 and switching to the Razor engine. Problem now is my text will not wrap within the treeview leaf node.

  mappings.For<ArticleSummary>(binding => binding
                        .ItemDataBound((leafItem, article) =>
                        {                           
                            //leafItem.Text = article.Abstract;                           
                            leafItem.SpriteCssClasses = "img-box3";
                            leafItem.Template.InlineTemplate =
                            @<text>
                               @* <div class="img-box3">*@
                                    @if (article.ContainsValidThumbNail()) 
                                      {
                                          <img src='@Url.Action("GetImageForArticleId", "Resources", new { id = article.Id })' alt=""/>                                
                                      }
                                      <div>@article.Abstract</div> 
                                      @if (article.ContainsMainText)
                                      {
                                          <a>@Html.ActionLink("Details", "Details", "News", new { newsId = article.Id }, null)</a>
                                      }
                                @*</div>   *@                           
                            </text>;
 
I want article.Abstract to wrap instead of being displayed on a single line with scroll bar enabled even though white-space is set to default for img-box3.   Any ideas?  TIA.
Tags
TreeView
Asked by
Klaus
Top achievements
Rank 1
Answers by
Klaus
Top achievements
Rank 1
Share this question
or