后台代码 protected void RptPosterManager_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { DateTime CurrentDataTime = DateTime.Now; DateTime strEndTime = Convert.ToDateTime(((Label)e.Item.FindControl("endtime")).Text); if (DateTime.Compare(CurrentDataTime, strEndTime) > 0) { //过期显示红色 ((HtmlTableRow)e.Item.FindControl("row")).Style.Add("background-color", "red !important"); ((HtmlTableRow)e.Item.FindControl("row")).Style.Add("color", "white !important"); } else { if (CurrentDataTime >= strEndTime.AddDays(-5)) { //将要过期显示黄色 ((HtmlTableRow)e.Item.FindControl("row")).Style.Add("background-color", "yellow !important"); } } } }
前台代码 <table class="stylized full" id="dispersion"> <caption><img src="../img/pencil.png" /> <a href="AddPoster.aspx">添加广告图片</a></caption> <thead> <tr> <th>序号</th> <th>图片</th> <th>广告位置</th> <th>链接地址</th> <th>开始时间</th> <th>结束时间</th> <%--<th>状态</th>--%> <th>操作</th> </tr> </thead> <tbody> <asp:Repeater ID="RptPosterManager" runat="server" onitemdatabound="RptPosterManager_ItemDataBound"> <ItemTemplate> <tr id="row" runat="server" > <td><%#Container.ItemIndex + 1%></td> <td><%#GetImagPath(Eval("Image").ToString(), Eval("ID").ToString())%></td> <td><%#Eval("AreaName")%></td> <td><%#Eval("LinkAddress")%></td> <td><%#Eval("BeginTimeStr") %></td> <td><asp:Label ID="endtime" runat="server" Text='<%#Eval("EndTimeStr") %>'></asp:Label></td> <%--<td><%#Eval("State").ToString() == "0" ? "启用" : "<span style='color:red'>禁用</span>"%></td><td><a href="javascript:void(0);" TagID='<%#Eval("ID") %>' name="delete">删除</a> | <a href='UpdatePoster.aspx?sCode=<%#Common.ApplicationMethods.EncryptOverride(Eval("ID").ToString()) %>'>修改</a> | <a href="javascript:void(0);" TagID='<%#Eval("ID") %>' name="updateState" TagState='<%#Eval("State") %>'><%#Eval("State").ToString() == "0" ? "<span style='color:red'>禁用</span>" : "启用"%></a></td>--%> <td><a href="javascript:void(0);" TagID='<%#Eval("ID") %>' name="delete">删除</a> | <a href='UpdatePoster.aspx?sCode=<%#Common.ApplicationMethods.EncryptOverride(Eval("ID").ToString()) %>'>修改</a></td> </tr> </ItemTemplate> </asp:Repeater> </tbody> </table>