---
title: "ASPX View MVC3 WebGrid format column"  
description: "ASPX View MVC3 WebGrid format column"  
author: "Mark Devid"  
published: 2014-11-20  
updated: 2014-11-20  
canonical: https://www.mindstick.com/forum/12651/aspx-view-mvc3-webgrid-format-column  
category: "asp.net"  
tags: ["asp.net mvc", "view", "grid", "web"]  
reading_time: 2 minutes  

---

# ASPX View MVC3 WebGrid format column

```
<%{     WebGrid studentGrid = new WebGrid(rowsPerPage: StudentController.PageSize);     studentGrid.Bind(Model.Students, autoSortAndPage: false, rowCount: Model.RowCount);     studentGrid.PageIndex = Model.CurrentPage;}%><%=studentGrid.GetHtml(columns: new WebGridColumn[]{    studentGrid.Column("StudentId", "Id"),    studentGrid.Column("Name", "Name"), })%>
```

Unfortunatly i am forced to use [aspx view](https://www.mindstick.com/interview/23259/differences-between-razor-and-aspx-view-engine-in-mvc) in my MVC3 project.

I want to have a [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) that [shows](https://yourviews.mindstick.com/view/81380/new-york-violent-shooting-shows-people-are-not-safe-in-night-life) a text "[select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance)" or "[remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden)" based on some [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) of the list item that is bound to the grid.

How is the sysntax to do that

I have to get [render](https://www.mindstick.com/interview/2205/why-we-need-a-separate-mobile-project-template-while-we-can-render-our-web-application-in-mobile-what-s-new-in-mvc-4-mobile-template) [html](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) like

<span [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="1" id=item.id>Select<span>

and the html shown will be just **Select**

## Replies

### Reply by Anonymous User

You can definitely do it with format you just need to handcraft the HTML in C#:

```
<%     var list = new[]                    {                        new { StudentId = 1, Name = "Name1", Cond = true },                        new { StudentId = 2, Name = "Name3", Cond = false },                        new { StudentId = 2, Name = "Name3", Cond = true },                    };    WebGrid studentGrid = new WebGrid();    studentGrid.Bind(list, autoSortAndPage: false, rowCount: 3);  %><%= studentGrid.GetHtml(columns:     new WebGridColumn[]        {            studentGrid.Column("StudentId", "Id"),            studentGrid.Column("Name", "Name"),            studentGrid.Column(header: "Action",                  format: item =>                {                    string span = "<span class=\"1\" id=\"{0}\">{1}<span>";                    string action = item.Cond ? "Select" : "Remove";                    return Html.Raw(string.Format(span, item.StudentId, action));                })        })%>
```

Using the aspx template systax (eg. <% %>) inside a lambda is supported in general (see this Telerik demo) but because the WebGrid working diffidently than Telrik it's not working.

It seems the way is WebGrid built only supports razor templates inside the format argument


---

Original Source: https://www.mindstick.com/forum/12651/aspx-view-mvc3-webgrid-format-column

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
