Hi,
If the "DM" is a scalar (i.e. a 1-by-1 matrix), you can simply use assignment (there is a conversion operator defined):
DM aaa = 3.2; // double to casadi::DM
double a = aaa; // casadi::DM to double
For your second question, please reread the user guide. You have to create a function object corresponding to the gradient and then evaluate it numerically.
Joel