Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top