日期:2014-05-18 浏览次数:20465 次
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim img1 As New Image Dim UpdateTime As DateTime img1.ImageUrl = "~/images/threeday.gif" '显示三天内更新 If Not Convert.IsDBNull(DataBinder.Eval(e.Row.DataItem, "UpdateTime")) Then UpdateTime = DataBinder.Eval(e.Row.DataItem, "UpdateTime") Dim ts1 As New TimeSpan(UpdateTime.Ticks) Dim ts2 As New TimeSpan(Now.Ticks) Dim ts As TimeSpan = ts1.Subtract(ts2).Duration() If ts.Days < 3 Then e.Row.Cells(5).Controls.Add(img1) End If End If End If End Sub
------解决方案--------------------
你可以这样写数据源:
select 字段1,字段2,....,DataDiff(day,PostTime,GetDate()) as days from xxx.....
这样,你搜索出来的数据源中就多了一个字段days,然后在信息后加个图片,建议用模板页
加上<img src='....' runat="server" visible='<%# Display(Eval("days"))%>'/>
后台CS
public bool Display(string days)
{
int day=int.parse(days);
if(day<=3)
return true;
else
return false;
}
------解决方案--------------------
<asp:TemplateField> <ItemTemplate> <b><%# Eval("Title") %></b> <asp:Image ID="imgNew" ImageUrl="Images/New.gif" runat="server" Visible='<%# Convert.ToDateTime(Eval("PublicTime")).AddDays(3) > DateTime.Now ? true : false %>'/> </ItemTemplate> </asp:TemplateField>