telerik网格根据使用服务器绑定的条件显示数据

telerik网格根据使用服务器绑定的条件显示数据,telerik,telerik-grid,telerik-mvc,Telerik,Telerik Grid,Telerik Mvc,我有一个telerik网格,我想如下显示数据 ProductName Count Letters 5 Phone Pens 3 我想做一些类似于如果计数>0,则只显示计数列的值,即不显示值0 <% Html.Telerik().Grid(Model.Orders) .Name("Grid") .Columns(columns => { columns

我有一个telerik网格,我想如下显示数据

ProductName Count
Letters     5
Phone   
Pens        3
我想做一些类似于如果计数>0,则只显示计数列的值,即不显示值0

<% Html.Telerik().Grid(Model.Orders)
             .Name("Grid")
            .Columns(columns =>
            {
                columns.Bound(o => o.ProductName);
   if(Count>0)
       {
                columns.Bound(o => o.Count);
       }    
              })
            .Groupable(settings => settings.Groups(groups => groups.Add(o => o.KeyID)).Visible(false))
            .Scrollable(s => s.Enabled(true))
            .Scrollable(scrolling => scrolling.Height(300))
            .Reorderable(reorder => reorder.Columns(true))
            .Footer(true)
            .Render();
        %>

{
columns.Bound(o=>o.ProductName);
如果(计数>0)
{
columns.Bound(o=>o.Count);
}    
})
.Groupable(settings=>settings.Groups(Groups=>Groups.Add(o=>o.KeyID)).Visible(false))
.Scrollable(s=>s.Enabled(true))
.可滚动(滚动=>滚动高度(300))
.Reorderable(reorder=>reorder.Columns(true))
.Footer(true)
.Render();
%>

谢谢

您可以使用CellAction来呈现条件结果

<%
Html.Telerik().Grid(Model.Orders)
.Name("Grid")
.CellAction(cell => 
  {
    if (cell.Column.Title.Equals("Count"))
    {
      if (cell.DataItem.Count == 0)
      {
        cell.Text = "&nbsp;";
      }
    }
  })
 .Columns(columns =>
  {
      columns.Bound(o => o.ProductName);
      columns.Bound(o => o.Count);
  })
.Groupable(settings => settings.Groups(groups => groups.Add(o => o.KeyID)).Visible(false))
.Scrollable(s => s.Enabled(true))
.Scrollable(scrolling => scrolling.Height(300))
.Reorderable(reorder => reorder.Columns(true))
.Footer(true)
%>

{
if(cell.Column.Title.Equals(“Count”))
{
if(cell.DataItem.Count==0)
{
cell.Text=“”;
}
}
})
.列(列=>
{
columns.Bound(o=>o.ProductName);
columns.Bound(o=>o.Count);
})
.Groupable(settings=>settings.Groups(Groups=>Groups.Add(o=>o.KeyID)).Visible(false))
.Scrollable(s=>s.Enabled(true))
.可滚动(滚动=>滚动高度(300))
.Reorderable(reorder=>reorder.Columns(true))
.Footer(true)
%>

您可以使用CellAction来呈现条件结果

<%
Html.Telerik().Grid(Model.Orders)
.Name("Grid")
.CellAction(cell => 
  {
    if (cell.Column.Title.Equals("Count"))
    {
      if (cell.DataItem.Count == 0)
      {
        cell.Text = "&nbsp;";
      }
    }
  })
 .Columns(columns =>
  {
      columns.Bound(o => o.ProductName);
      columns.Bound(o => o.Count);
  })
.Groupable(settings => settings.Groups(groups => groups.Add(o => o.KeyID)).Visible(false))
.Scrollable(s => s.Enabled(true))
.Scrollable(scrolling => scrolling.Height(300))
.Reorderable(reorder => reorder.Columns(true))
.Footer(true)
%>

{
if(cell.Column.Title.Equals(“Count”))
{
if(cell.DataItem.Count==0)
{
cell.Text=“”;
}
}
})
.列(列=>
{
columns.Bound(o=>o.ProductName);
columns.Bound(o=>o.Count);
})
.Groupable(settings=>settings.Groups(Groups=>Groups.Add(o=>o.KeyID)).Visible(false))
.Scrollable(s=>s.Enabled(true))
.可滚动(滚动=>滚动高度(300))
.Reorderable(reorder=>reorder.Columns(true))
.Footer(true)
%>

实际上它只适用于服务器绑定。我刚刚编辑了答案。我错误地将==0改为>0。此外,我猜引号中一定有类似“”的内容。请参阅编辑。实际上,它仅适用于服务器绑定。我刚刚编辑了答案。我错误地将==0改为>0。此外,我猜引号中一定有类似“”的内容。请参见编辑。