第一步:這樣寫Sql語句:
select top 5 PK_Rntol_ID,Title,RenoDate,Promulgator,Flag=case
when getdate() - RenoDate < 5 then '1'
else '0'
end
from esintypzb.T_Info_Rntol where RenoKind= @type order by RenoDate desc
第二步:
在DataGrid的DataBound()方法裡面:
/// <summary>
/// 根據日期的多寡,決定是否顯示new圖標
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void wgrd_Info_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if(e.Item.Cells[5].Text == "1")
{
e.Item.Cells[1].Text = e.Item.Cells[1].Text + " <img src=../../Images/new.gif>";
}
}
}