I want to change the color of gridview row according to sysdate
How to change color of row after 4th day?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Khargesh RajputRank #616 · 3.9K reputationPosted Feb 9, 2015, 1:51 AM EST
e.Row.BackColor = Drawing.Color.red
on row databound
for 4th day check if day diff (system date and record insert date)>=4
then
e.Row.BackColor = Drawing.Color.red
Sanket JainRank #1,789 · 835 reputationPosted Feb 10, 2015, 12:38 AM EST
I'm using following code :
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToDateTime(e.Row.Cells[8].Text) < DateTime.Now)
{
e.Row.BackColor = Color.Red;
e.Row.ForeColor = Color.White;
}
}
but it will give error like "String was not recognized as a valid DateTime."
So what can I do ?
Khargesh RajputRank #616 · 3.9K reputationPosted Feb 10, 2015, 1:08 AM EST
or
if (Convert.ToDateTime(e.Row.Cells[8].Text.tostring("dd/mm/yyyy")) < DateTime.Now.tostring("dd/mm/yyyy"))
{}
keyurRank #5,481 · 298 reputationPosted Feb 10, 2015, 1:22 AM EST
Can you please check,is cell text coming blank ? If so it will give error.
Sanket JainRank #1,789 · 835 reputationPosted Feb 10, 2015, 2:05 AM EST
So how to solve this error?
keyurRank #5,481 · 298 reputationPosted Feb 10, 2015, 2:11 AM EST
For conver into datetime use like below
DateTime dt = DateTime.ParseExact(dateString, "ddMMyyyy",
CultureInfo.InvariantCulture);
dt.ToString("yyyyMMdd");
and check if text empty do not parse
Sanket JainRank #1,789 · 835 reputationPosted Feb 10, 2015, 11:13 PM EST
Any another method is their for that ?
Francis SusaimichaelRank #466 · 5.4K reputationPosted Feb 11, 2015, 2:37 AM EST
Sanket JainRank #1,789 · 835 reputationPosted Feb 11, 2015, 8:18 PM EST
If this date is greater than sysdate then the color of row will be change
keyurRank #5,481 · 298 reputationPosted Feb 11, 2015, 8:21 PM EST
Please check below code and write in row bound
protected void grdDoc _RowDataBound(object sender, GridViewRowEventArgs e)
{
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) ||
(e.Row.Cells[3].Text != " "))
{
Char result = Convert.ToInt32(e.Row.Cells[3].Text);
if (result == 'Y') e.Row.BackColor = System.Drawing.Color.Aqua;
else if (result =='N') e.Row.BackColor = System.Drawing.Color.Cornsilk;
}
}
}
}