【问题标题】:Header Format for WebGridWebGrid 的标题格式
【发布时间】:2011-07-21 17:57:40
【问题描述】:

我刚刚阅读:http://www.mikesdotnetting.com/Article/154/Looking-At-The-WebMatrix-WebGrid 并看到对[Optional, Default Value(null)] string header 的引用

如果您不需要数据库字段名称,则为标题文本

但我不确定如何格式化单元格值。例如,如果我有一个如下所示的 WebGrid:

Column Name          Column Name          Column Name          Column Name          
Cell value           Cell value           Cell value           Cell value           
Cell value           Cell value           Cell value           Cell value           
Cell value           Cell value           Cell value           Cell value           
Cell value           Cell value           Cell value           Cell value           
Cell value           Cell value           Cell value           Cell value           

我想让每个单元格都可以点击,并且根据它所在的列,我希望其对应的超链接与另一个单元格的超链接不同。

这可以使用 WebGrid 完成吗?我已经在 PHP 中完成了这项工作,但不知道在哪里查看,或者如何使用 WebGrid 来完成。

在搜索 Google、Bing 和 Yahoo!(?) 时,我只看到那些高级 WebGrid 组件的结果,而不是真正的 WebGrid 的单个结果,也没有任何有帮助的结果。

【问题讨论】:

标签: c# asp.net razor webmatrix webgrid


【解决方案1】:

在您引用的 Mike 的 DotNetting 文章中,他展示了如何在以下代码行中显示短日期:

format: @<text>@item.DatePublished.ToShortDateString()</text>

由于格式替换了整个单元格,您只需输入生成所需 HTML 的代码,包括超链接。由于生成任何复杂的东西可能会使那行代码阅读起来太痛苦,因此最好编写自己的类/函数来生成所需的代码。我有这样的情况,我的格式行看起来像:

format : @<text>@Html.Raw(NDisplay.displayComment( username, item.AssignedTo, item.NALComment, item.refID, item.Process))</text>,

然后在那个函数中:

public static string displayComment( string username, string AssignedTo, string NALComment, int refID, string Process) 
{
    // various junk code removed, testing user and rights
    // here we know we have the right user, he or she needs the edit URL
    // two parameters are passed, first the refID, second the Process (or document)
    string e = "<a href =\"../Process/" + refID.ToString() + "/" + Process +"/\">Edit</a> " + NALComment;

    return e;
}

在每个单元格中,都有一个编辑超链接,后跟一个文本注释。

【讨论】:

  • 如果您正在编写自己的自定义函数来生成 HTML,您应该使用 Helper:mikesdotnetting.com/Article/173/…
  • @Mike Brind,非常有趣。我没有考虑到这一点,因为该函数位于列定义中。
  • @Mike - 谢谢,我现在就试一试!
  • 谢谢,但这仍然行不通。所有这些格式的东西总是显示相同的错误。
  • 对不起,它工作得很好。我只是忘了刷新页面。 (有一个非常金发的一天)。以下效果很好:格式:@Jason Rules
猜你喜欢
  • 2011-06-19
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 2012-10-24
  • 2012-12-01
  • 2013-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多