我有一个功能和asp.net;请将第一个函数中的注释视为问题。
如果我的方法不好,请分享您的想法。我是asp.net的新手。 =)
protected String DelayedText(object base__id_with_time, object file_name_with_time)
{
DateTime _dateTime1= Convert.ToDateTime(base__id_with_time);
DateTime _dateTime2= DateTime.ParseExact(file_name_with_time, "dd-MM-yyyy-HH-mm-ss", CultureInfo.InvariantCulture);
int timeDifference = DateTime.Compare(_dateTime1 , _dateTime2);
if (timeDifference >= 1)
{
//how to set that certain gridview cell's background color to red here please?
}
return timeDifference.ToString();
}
<asp:TemplateField HeaderText="Delayed" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="DelayedCheck" runat="server" Text='<%# DelayedDeliveryText(Eval("CreateDate"),Eval("FileName"))%>'
/>
</ItemTemplate>
</asp:TemplateField>
任何想法都表示赞赏。谢谢=)
答案 0 :(得分:0)
这是您的解决方案。根据你的代码:让Gridview名称是“grvData”
//how to set that certain gridview cell's background color to red here please?
foreach (GridViewRow row in grvData.Rows)
{
Label lblDelayedCheck= ((Label)row.FindControl("DelayedCheck")).Text;
lblDelayedCheck.Cells[CellIndexNo].BackColor = Color.Red;
}