日期:2012-05-16  浏览次数:20475 次

页面代码如下:
<asp:datagrid id="myGrid1" GridLines="None" PageSize="7" ShowHeader="False" AllowPaging="True"
CellPadding="0" AutoGenerateColumns="False" Height="100%" Width="224px" runat="server">
<ItemStyle Font-Size="12px" HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="ID" DataNavigateUrlFormatString="Detail.aspx?ID={0}"
DataTextField="Title"></asp:HyperLinkColumn>
<asp:TemplateColumn>
<ItemTemplate>
<img src='<%# (Convert.ToInt16(DataBinder.Eval(Container.DataItem,"DayCount"))<15)? "images/new.gif" :
"images/none.gif"%>' border="0" >
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Visible="False"></PagerStyle>
</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类型的字段,是指发布日期