Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:40:48+00:00 2026-06-04T17:40:48+00:00

<%{ WebGrid studentGrid = new WebGrid(rowsPerPage: StudentController.PageSize); studentGrid.Bind(Model.Students, autoSortAndPage: false, rowCount: Model.RowCount); studentGrid.PageIndex =

  • 0
<%{
     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 in my MVC3 project.

I want to have a column that shows a text “select” or “remove” based on some condition of the list item that is bound to the grid.

How is the sysntax to do that

I have to get render html like

<span class="1" id=item.id>Select<span>

and the html shown will be just Select

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:40:49+00:00Added an answer on June 4, 2026 at 5:40 pm

    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…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

@{ var grid = new WebGrid(Model.Auctions, rowsPerPage: Model.PagingInfo.ItemsPerPage, defaultSort: AddedDate); } @grid.GetHtml( columns: grid.Columns(
@{ var gridUser = new WebGrid(canPage: true, defaultSort: CreatedOn, rowsPerPage: 5, ajaxUpdateContainerId: Divxyz); gridUser.Bind(Model.abc,
I'm calling stored procedure: ObjectResult<ComplexType1> result = context.ListSomething(model.SelectedDatabase); ViewBag.WebGrid = new WebGrid(source: result, rowsPerPage:
I'm trying to use a WebGrid to display data in my model and am
I have a WebGrid tied to a model. In my model I have a
I passed List as Model to WebGrid Constructor. @model List<string> @{ var grid =
I'm new to MVC so have some conceptual issues. I have a WebGrid that
@model MedicalVariance.Models.ViewModels.IndividualProfile @Html.ListBox(AdministrationErrorSelected, Model.AdministrationErrorListBox, new { @class = chzn-select }) It look great and
I am able to use WebGrid in any controller like: var grid = new
I've implemented a WebGrid. Sorting, paging and filtering do not work together. They work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.