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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
keyurPosted Feb 12, 2015, 1:21 AM
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;
}
}
}
}
Sanket JainPosted Feb 12, 2015, 1:18 AM
If this date is greater than sysdate then the color of row will be change
Francis SusaimichaelPosted Feb 11, 2015, 7:37 AM
Sanket JainPosted Feb 11, 2015, 4:13 AM
Any another method is their for that ?
keyurPosted Feb 10, 2015, 7:11 AM
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 JainPosted Feb 10, 2015, 7:05 AM
So how to solve this error?
keyurPosted Feb 10, 2015, 6:22 AM
Can you please check,is cell text coming blank ? If so it will give error.
Khargesh RajputPosted Feb 10, 2015, 6:08 AM
or
if (Convert.ToDateTime(e.Row.Cells[8].Text.tostring("dd/mm/yyyy")) < DateTime.Now.tostring("dd/mm/yyyy"))
{}
Sanket JainPosted Feb 10, 2015, 5:38 AM
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 RajputPosted Feb 9, 2015, 6:51 AM
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