如何用DataGrid实现根据日期判断是否显示New标志

页面代码如下:

 1<asp:datagrid allowpaging="True" autogeneratecolumns="False" cellpadding="0" gridlines="None" height="100%" id="myGrid1" pagesize="7" runat="server" showheader="False" width="224px">
 2<itemstyle font-size="12px" horizontalalign="Left" verticalalign="Middle"></itemstyle>
 3<columns>
 4<asp:hyperlinkcolumn datanavigateurlfield="ID" datanavigateurlformatstring="Detail.aspx?ID={0}" datatextfield="Title"></asp:hyperlinkcolumn>
 5<asp:templatecolumn>
 6<itemtemplate>
 7<img border="0" src='```
 8# (Convert.ToInt16(DataBinder.Eval(Container.DataItem,"DayCount"))&amp;lt;15)? "images/new.gif" :   
 9"images/none.gif"
10```'/>
11</itemtemplate>
12</asp:templatecolumn>
13</columns>
14<pagerstyle visible="False"></pagerstyle>
15</asp:datagrid>

后台代码:
SqlConnection con=new SqlConnection (ConfigurationSettings.AppSettings ["strconn"]);
con.Open ();
SqlCommand cmd=new SqlCommand ("select id,Title,datediff(day,sendDate,getdate()) as DayCount from NewInfo",con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet ();
da.Fill (ds);
con.Close ();
myGrid1.DataBind();
//sendDate是一个DateTime类型的字段,是指发布日期

Published At
Categories with Web编程
Tagged with
comments powered by Disqus