2011-08-05 9 views
6

Telerik MVC3グリッドを使用すると、C#、.Net 2010;Telerikグリッド(MVC3)のマルチラインセル

私はかみそりビューでグリッドを持っています。

@(Html.Telerik().Grid<ProductListItem>() 
.Name("Grid") 
.Columns(columns => 
{ 
     columns.Bound(o => o.Current.Name).Sortable(true).Filterable(false).Width(150); 
     columns.Bound(o => o.Categories).Sortable(true).Filterable(false).Width(200); 
     //other column bindings... 
}) 
.DataBinding(dataBinding => dataBinding.Ajax().Select(Model.GridAjaxRequestAction.ActionName, Model.GridAjaxRequestAction.ControllerName)) 
.Pageable(settings => settings.Total(Model.TotalRow)) 
.EnableCustomBinding(true) 
.Sortable() 
.Filterable() 

複数行としてグリッドのカテゴリー列を設定している私は何をしたいです。

グリッド内のカテゴリセルが同じであるように、製品には多くのカテゴリが存在することがあります。

Category0 
Category1 
Category2 

私はSystem.NewLineと
でカテゴリ値に参加して、ProductListItem.Categoriesプロパティにこの値を割り当てようとしました。それは変わらない。テキストはまだ単一行です。

ありがとうございます。

答えて

4

ありがとうございます@nekno。私は私の場合、この解決策を思いついた。しばらくのうちに返答して申し訳ありません。ビューにおける

this.Categories = String.Join("<br>", entity.Categories.Select(o => o.Current.Name));

:ビューモデルにおける

columns.Bound(O => o.Categories).ClientTemplate( "<#=カテゴリー#>")

1

NewLineで結合しようとすると簡単な場合はSystem.NewLineの代わりに"<br />"を試してください。

それ以外の場合、ProductListItem.Categoriesプロパティのデータタイプは何ですか? List<String>またはその他のIEnumerableの場合は、バインドされた列の代わりにテンプレート列を使用できます。あなたは、テンプレート内の現在ProductListItemを参照するためにitemを使用します。

@(Html.Telerik().Grid<ProductListItem>() 
.Name("Grid") 
.Columns(columns => 
{ 
     columns.Bound(o => o.Current.Name).Sortable(true).Filterable(false).Width(150); 
     columns.Template(
      @<text> 
       @String.Join("<br />", item.Categories) 
      </text>) 
      .Sortable(true).Filterable(false).Width(200); 
     //other column bindings... 
}) 
.DataBinding(dataBinding => dataBinding.Ajax().Select(Model.GridAjaxRequestAction.ActionName, Model.GridAjaxRequestAction.ControllerName)) 
.Pageable(settings => settings.Total(Model.TotalRow)) 
.EnableCustomBinding(true) 
.Sortable() 
.Filterable() 

は別のオプションは、テンプレート列にテーブルを作成すること、そして去るかもしれないあなたのProductListItem.CategoriesListとして例えば、this.Categories = entity.Categories.Select(o => o.Current.Name).ToList();

@(Html.Telerik().Grid<ProductListItem>() 
    .Name("Grid") 
    .Columns(columns => 
    { 
      columns.Bound(o => o.Current.Name).Sortable(true).Filterable(false).Width(150); 
      columns.Template(
       @<text> 
        <table border=0> 
         @foreach(var category in item.Categories){ 
          <tr><td>@category</td></tr> 
         } 
        </table> 
       </text>) 
       .Sortable(true).Filterable(false).Width(200); 
      //other column bindings... 
    }) 
    .DataBinding(dataBinding => dataBinding.Ajax().Select(Model.GridAjaxRequestAction.ActionName, Model.GridAjaxRequestAction.ControllerName)) 
    .Pageable(settings => settings.Total(Model.TotalRow)) 
    .EnableCustomBinding(true) 
    .Sortable() 
    .Filterable() 
+0

ProductListItem.Categoriesプロパティは結合された文字列として来ています。 this.Categories = String.Join( "
"、entity.Categories.Select(o => o.Current.Name));私はテンプレートアドバイスを使ってこれとあなたのアドバイスを試みましたが、それはまだ同じです:/。 – berdem

+0

@berdem - ブラウザでHTMLソースを表示し、複数のカテゴリを持つその表のセルに表示されているものをここに貼り付けることはできますか? – nekno

関連する問題