为的WebGrid标题格式 [英] Header Format for WebGrid

查看:303
本文介绍了为的WebGrid标题格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看了: HTTP://www.mikesdotnetting。 COM /条/ 154 /展望 - 在最WebMatrix中-的WebGrid 并看到 [可选,默认值(NULL)串头 如果你不想数据库字段名

标题文字

但我不知道如何格式化单元格值。举例来说,如果我有一个的WebGrid,看起来像这样:

 列名列名列名列名
单元格值单元格值单元格值单元格的值
单元格值单元格值单元格值单元格的值
单元格值单元格值单元格值单元格的值
单元格值单元格值单元格值单元格的值
单元格值单元格值单元格值单元格的值

我想使每一个细胞可点击,并且根据它在专栏中,我想其相应超链接来自另一个细胞的超链接不同。

可以这样使用的WebGrid做什么?我这样做在PHP中,但不知道去哪里找,或者如何使用的WebGrid做到这一点。

一旦谷歌搜索,Bing和雅虎(?),我只看到那些premium的WebGrid组件,而不是真正的WebGrid一个结果,也没有任何结果,这将是有帮助的结果。


解决方案

在Mike的DotNetting文章您引用,他展示了如何在下面的行code的显示shortdate:

 格式:@<文字和GT; @ item.DatePublished.ToShortDateString()< /文字和GT;

由于格式替换整个单元格,你只需要把code产生你想要的HTML,包括超链接。由于产生复杂的东西可能使该行code太痛苦了阅读的,它可能是最好写自己的类/函数产生你想要的code。我有这样的情况,我的格式线如下:

 格式:@<文字和GT; @ Html.Raw(NDisplay.displayComment(用户名,item.AssignedTo,item.NALComment,item.refID,item.Process))LT; /文字>中

,然后在功能:

 公共静态字符串displayComment(用户名字符串,字符串AssignedTo,串NALComment,诠释REFID,字符串处理)
{
    //各种垃圾code去掉,测试用户和权限
    //这里我们知道我们有正确的用户,他或她需要编辑网址
    //两个参数传递,首先是REFID,第二个过程(或文件)
    串E =< A HREF = \\../流程/+ refID.ToString()+/+流程+/ \\>编辑< / A>中+ NALComment;    返回e的;
}

在每个单元中,有一个编辑的超链接,接着文本注释

I just read: http://www.mikesdotnetting.com/Article/154/Looking-At-The-WebMatrix-WebGrid and see a reference to [Optional, Default Value(null)] string header

Header text if you don't want database field names

But I'm not sure how to format cell values. For example, if I have a WebGrid that looks like this:

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           

I would like to make each Cell clickable, and depending on the column it is in, I would like its corresponding hyperlink to be different from another cell's hyperlink.

Can this be done using WebGrid? I've done this in PHP, but have no idea where to look, or how to do it with WebGrid.

Upon searching Google, Bing and Yahoo!(?), I only see results for those premium WebGrid components, not a single result for the real WebGrid, nor any results that would be of any help.

解决方案

In Mike's DotNetting article that you reference, he shows how to display the shortdate in the following line of code:

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

Since the format replaces the entire cell, you just need to put the code that produces the HTML you want, including hyperlinks. Since to produce anything complicated might make that line of code too painful to read, it might be best to write your own class/function that produces the code you want. I have a situation like that and my format line looks like:

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

And then in that function:

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;
}

In each cell, there's an edit hyperlink, followed by a text comment.

这篇关于为的WebGrid标题格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆