Change ASP.Net DataList Cell Background Color based on condition using C# and VB.Net

Last Reply 6 months ago By pandeyism

Posted 6 months ago

i have datalist in which one column latedays has digit.

now i want when digits greater than 0 then lateday cell get red. 

Kindly guide thanks. 

here is my c# code

        DataTable dt = new DataTable();
        dt.Clear();
        dt.Columns.Add("TDID");
        dt.Columns.Add("TDDesc");
        dt.Columns.Add("taskdate");
        dt.Columns.Add("enddate");
        dt.Columns.Add("TDstatus");
        dt.Columns.Add("latedays");
        dt.Columns.Add("TDTYPE");

        SqlCommand cmd1 = con.CreateCommand();
        cmd1.CommandType = CommandType.Text;
        cmd1.CommandText = "select TODOLIST.TDID, TODOLIST.TDDesc,Convert(varchar(12),TODOLIST.taskdate,101) as taskdate ,TODOLIST.enddate,TODOLIST.TDstatus,TODOLIST.TDTYPE " +
        " from TODOLIST inner join employee on TODOLIST.empid=employee.empid  where TDstatus ='Open'and employee.EmpID= '" + Session["EmpID"].ToString() + "'";
        cmd1.ExecuteNonQuery();
        DataTable dt1 = new DataTable();
        SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
        da1.Fill(dt1);
        foreach (DataRow dr1 in dt1.Rows)
        {
            DataRow dr = dt.NewRow();
            dr["TDID"] = dr1["TDID"].ToString();
            dr["TDDesc"] = dr1["TDDesc"].ToString();
            dr["taskdate"] = dr1["taskdate"].ToString();
            dr["enddate"] = dr1["enddate"].ToString();
            dr["TDstatus"] = dr1["TDstatus"].ToString();
            dr["TDTYPE"] = dr1["TDTYPE"].ToString();
            DateTime d1 = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd"));
            DateTime d2 = Convert.ToDateTime(dr1["enddate"].ToString());
            if (d1 > d2)
            {
                TimeSpan t = d1 - d2;
                double noofday = t.TotalDays;
                dr["latedays"] = noofday.ToString();
            }
            else
            {
                dr["latedays"] = "0";
            }
            dt.Rows.Add(dr);
        }
        d3.DataSource = dt;
        d3.DataBind();
    }

 

This question does not have replies that have been liked.