日期:2014-05-18  浏览次数:20499 次

设定gridview显示列内容格定
请教,使用gridview显示数据库中的内容,当其字段显示日期内容时怎样可以只显示 "年-月-日 "格式?怎样解决?

------解决方案--------------------
string date = "1900-1-1 0:00:00 ";
Convert.ToDateTime(date).ToShortDateString().ToString();
------解决方案--------------------
最简单例子
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " OnRowDataBound= "GridView1_RowDataBound ">
<Columns>
<asp:BoundField DataField= "bandfield " HeaderText= "备案日期 " />
</Columns>
</asp:GridView>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = Convert.ToDateTime(e.Row.Cells[0].Text).ToShortDateString().ToString();
}
}