I would like to set radio buttons checked base on results from query such as in my case its a medical questionnaire. A medical questionnaire results last quite a while.
So if user do not have a valid medical questionnaire, the use will be directed to a empty questionnaire page to select the yes or no radio buttons. Part of the coding of the questionnaire looks like this:
<tr>
<td width="33">1.</td>
<td width="491">Heart or circulatory problems including: high blood pressure, heart attack, angina, heart murmur, heart failure, palpitations, circulatory problemseg. whitefinger, blocked arteries, stroke aneurysm.</td>
<td width="68"><input name="medq1" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label></td>
<td width="78"><input name="medq1" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label></td>
There are 20 over question but i am not going to post all as it will be confusing.
However if the user have a valid medical questionnaire stored in the database,when he apply for the permit, he will be redirected to the same questionnaire page, but instead of it being empty, the radio button of yes and no should be checked base on the result from the SQL query.
var sql = "SELECT * FROM Medical WHERE CDSID = @0";
var MedicalResult = db.QuerySingle(sql,myCDSID);
var myQ1 = MedicalResult.Q1;
:
:
:
var myQ20 = MedicalResult.Q20;
So now the results are stored in variables and we can use the variables as the result to tell the radio button which must be checked.
However, I am noob beginner in Razor C# and I only know very very minimum but still in the learning process. I know the codes in PHP but not in Razor C#
In php, pretend we have the results from the sql already.
<input <?php if ($myQ1 == 'yes'){ echo 'checked="checked"'; } else { } ?> name="medq1" id="yes" type="radio" value="yes" onclick="displayTextBox()" /><label for="yes"> Yes </label>
<input <?php if ($myQ1 == 'no'){ echo 'checked="checked"'; } else { } ?> name="medq1" id="no" type="radio" value="no" onclick="displayTextBox()"/><label for="no"> No </label>
But how do I do this in Razor C#??
Thanks in advance for guidance. Still in learning process.