Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to insert current time on gridview in asp.net?
Posted
Updated 27-Mar-14 4:17am
v2
Comments
Tom Marvolo Riddle 27-Mar-14 5:33am    
Not clear.Improve the question
Oshtri Deka 27-Mar-14 10:19am    
What do you want? Current time somewhere in the header?
Or in the specific cell?
Or...

You can add a new column by clicking on gridview smarttag and add a item template something like this.

<asp:templatefield headertext="Currentdate" xmlns:asp="#unknown">
      <itemtemplate>
         <asp:label id="Label1" runat="server" text="<%# DateTime.Now.ToString() %>"></asp:label>
      </itemtemplate>
</asp:templatefield>

Modify the date format according to your need.
Good Luck
 
Share this answer
 
To show current time you can try this:
using System;
using System.Data;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
  public class Form1 : Form
  {
    DataGridView dgv = new DataGridView();
    public Form1()
    {
      this.Controls.Add(dgv);
      DataTable dt = new DataTable();
      dt.Columns.Add("Current Time", typeof(DateTime));
      dt.Rows.Add(new object[] { DateTime.Now });
      dgv.DataSource = dt;
      dgv.Columns[0].DefaultCellStyle.Format = "HH:mm:ss";
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900