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
I've been trying to change the format of a single column in a WebGrid
I am trying to format a WebGrid column so I can concatenate two pieces
Here is an example: I have a file 1.js, which has some functions. I
Here my code: $(document).ready(function() { $('#mid_select').live('click', function(e){ $('#middle').load( $(this).attr('href') + ' #middle'); var page
here is a debatable question which i want to achieve not sure how .
Here is the piece of code which I use to get the count from
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is the problem I'm trying to solve for my game. I have this
Here is my problem. Our tech. writer or customer service will often create new

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.