如何在asp.net中的gridview上插入当前时间? [英] How to insert current time on gridview in asp.net?
本文介绍了如何在asp.net中的gridview上插入当前时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在asp.net?
How to insert current time on gridview in asp.net?
推荐答案
中的gridview上插入当前时间您可以通过单击gridview smarttag添加新列并添加类似的项目模板这个。
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
要显示当前时间,您可以尝试:
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";
}
}
}
这篇关于如何在asp.net中的gridview上插入当前时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文