3

我刚刚阅读: 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 的单个结果,也没有任何有帮助的结果。

4

1 回答 1

2

在您引用的 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;
}

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

于 2011-03-24T11:54:09.163 回答