我数据库里有个字段是smallDateTime类型,但是在GridView中显示时现实了长时间格式:2007-1-1 0:00:00我想在GridView中现实短的时间格式,我看了数据库里的数据也是短的时间格式,为什么现实出来就变成长的了呢?我通过后台FormatDateTime方法,
<asp:TemplateField HeaderText="date">
  <ItemTemplate>
   <asp:Label ID="Label1" runat="server" Text='<%# FormateDateTime((Conver.ToDateTime(Eval("date"))) %>'>       </asp:Label>                            
  </ItemTemplate>
</asp:TemplateField>后台程序:
FormatDateTime(DateTime dateTime)
{
 ....
}
但是总是提示我无法转换请问如何能完成我想要的结果,万分感谢!

解决方案 »

  1.   

    FormatDateTime(DateTime dateTime)
    {
     return dateTime.ToShortDateString();
    }
      

  2.   

    <asp:BoundField DataField="Time" HtmlEncode=false DataFormatString="{0:yyyy年MM月dd日}"  HeaderText="Time" />
     HtmlEncode=false DataFormatString="{0:yyyy年MM月dd日}"  这里就能改变格式
      

  3.   

    选取数据源用的什么类型?datatime?
    你肯定是把段类型又转成长的了
      

  4.   

    smallDateTime是数据库中的类型,C#读取其中的内容初始化一个DateTime的变量,用0来填充时,分,秒这些字段
      

  5.   

    如果在GridView中直接这样就可以实现!
    <asp:BoundField DataField="processDate" HeaderText="申请日期" DataFormatString="{0:d}" HtmlEncode="False" />自己试试看!!!