我想改變到期字段的顏色。我想將該列的值與今天的日期進行比較,如果過期,則將其標記爲紅色。不是每一行都有一個值。所有這些數據都與GridView中顯示的SQL數據源相關聯。當我嘗試通過DataRowBound執行代碼時,它告訴我「字符串未被識別爲有效日期時間」在這裏有任何幫助?我希望它影響過期字段和行動比較日期到今天在一些空單元格的gridview
謝謝!
protected void GridView1_DataBound(object sender, EventArgs e)
{
if (GridView1.Rows[0].Cells[0].Text.Equals("Vendor"))
GridView1.Rows[0].Visible = false;
colorRed();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime myDate = Convert.ToDateTime(e.Row.Cells[10].Text);
if (DateTime.Now < myDate)//10 is for the expired field
{
e.Row.ForeColor = System.Drawing.Color.Red;
}
}
}
我有代碼綁定在html中,所以我能做些什麼來解決這個問題?
檢查'e.Row.Cells [10] .Text'爲空白或空** **之前將其轉換爲DateTime –