My Technical Notes

Thursday, 22 April 2010

Using MvcContrib's Html Grid and Pager

To use MvcContrib's Html Grid and Pager you need to include references to both Microsoft.Web.Mvc.dll and MvcContrib.dll which are included in MvcContrib. In your aspx file you need to include the following namespaces:

<%@ Import Namespace="MvcContrib.UI.Pager" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>

For hyperlinks you will want to include a statement to DoNotEncode on the column:

column.For(x => "<a href='javascript:void(0)'>Some Link</a>").DoNotEncode();

To apply attributes on the td tag of a particular column then you can do so with a call to Attributes extension method:

column.For(x => x.Id).Attributes(style => "background-color: red", @class => "redCell");

Occasionally you need access to the underlying object when deciding on the style of a table cell. For example, you may want to highlight all unread items with the color red:

column.For(x => x.Description)
      .Attributes(row =>
          new MvcContrib.Hash(style =>
                  if (!row.Item.IsRead) return "background-color: red";
                  else return "";

As you can see above, you can access the rows object by using row.Item.

You can find more information from David Hayden's blog and Jerry Skinner's blog.

No comments: