如题:datalist模版列中绑定一个数据库字段
显示的时间如下:2007-4-11 0:00:00
想要它只显示日期部分
部分代码:
mycmd.Parameters.Add( "@scjg_time ",SqlDbType.DateTime,8, "scjg_time ");
mycmd.Parameters[ "@scjg_time "].Value=DateTime.Now.Date.ToString( "yyyy-MM-dd ");
private void ScjgDataBind()
{
connString =System.Configuration.ConfigurationSettings.AppSettings[ "DSN "];
//string sql = "select * from scjg ";
string sqlString = ViewState[ "user.search.mySql "].ToString();
//----------
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connString;
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlString,conn);
DataSet ds = new DataSet();
da.Fill(ds, "scjg ");
//----------
ScjgDataList.DataSource = ds.Tables[ "scjg "];
ScjgDataList.DataBind();
ds.Clear();
conn.Close();
}
------解决方案--------------------------------------------------------
select * from scjg
-->
select convert(varchar(10), fielddate, 20) as fielddate, fieldother from scjp
------解决方案--------------------------------------------------------
<#Eval( "YourDate ", "{0:yyyy-MM-dd} ")>
------解决方案--------------------------------------------------------
两种方法
1.在DataGrid 的属性分析器里面,设置时间列的数据格式表达试为{0:yyyy-MM-dd}
2.在SQL语句中查询时间列用格式先转换,convert(varchar(10),fielddate,121) as fielddate