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 7896811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:59:24+00:00 2026-06-03T07:59:24+00:00

Here is my webgrid .I am trying to add a column EndDate which displays

  • 0

Here is my webgrid .I am trying to add a column “EndDate” which displays a calculated value

var grid = new WebGrid(canPage: true, rowsPerPage: Model.PageSize, canSort: true, ajaxUpdateContainerId: "grid");
    grid.Bind(Model.MyRecords, rowCount: Model.TotalRecords, autoSortAndPage: false);

    grid.Pager(WebGridPagerModes.All);
    @grid.GetHtml(htmlAttributes: new { id = "grid" },
                        columns: grid.Columns(

                        grid.Column("StartDate", "Live Date"),
                        grid.Column("EndOffsetSeconds", "End in Seconds"),
                        grid.Column("StartDate"+TimeSpan.FromSeconds("OffsetSeconds"), "Difference"),

                        grid.Column(header: "Action", format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.ID })),
                        grid.Column(format: (item) => Html.ActionLink("Copy", "CopyRecord", new { id = item.ID }))

                    ));

I want to show EndDate in place of third column .

Enddate = StartDate+TimeSpan.FromSeconds(EndOffsetSeconds)

On the 3rd column I want to show result of StartDate+TimeSpan.FromSeconds(EndOffsetSeconds)

where StartDate is of DateTime type and EndOffsetSeconds is of type Integer

Example DateTime StartDate =05/20/2012 12:15:03
int EndOffsetSeconds=124000;

How to add a computed column with a Webgrid ?

Thank you in advance

  • 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-03T07:59:26+00:00Added an answer on June 3, 2026 at 7:59 am

    You can add a property to your model and do the calculation in the get method.

    class MyRecord
    {
      public DateTime StartDate {get;set;}
      public int EndOffsetSeconds {get;set;}
    
      public DateTime CalculatedEndTime
      {
        get
        {
          return StartDate + TimeSpan.FromSeconds( EndOffsetSeconds );
        }
      }
    }
    

    Then just point to the calculated property in your grid.

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

Sidebar

Related Questions

I'm trying to add a checkbox to a column on a web grid, and
Here is my problem.. I have the option to create(add) two new input fields,
I am trying to format a WebGrid column so I can concatenate two pieces
I've been trying to change the format of a single column in a WebGrid
I am having a similar as the user here: ASP.NET MVC 3.0 WebGrid -
Here is the code in a function I'm trying to revise. This example works
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Been trying to do an update on a Kendo grid and I'm having issues.
Using an asp.net mvc webgrid, is it possible to render a column using Html.DisplayFor
I have the following WebGrid in my ASP.NET MVC3 test application. It displays a

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.