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:
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.
sorry...but how do i check which version is my razor if i am using webmatrix 2 beta. Does this mean it is most like razor v2?? sorry for this noob question.
hubertjiang
0 Points
21 Posts
How do i write this particular condition in Razor C#?
Apr 21, 2012 01:13 AM|LINK
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:
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.
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.
Radiobutton C RAZOR php
subhash.shel...
Contributor
2137 Points
487 Posts
Re: How do i write this particular condition in Razor C#?
Apr 21, 2012 01:48 AM|LINK
Hi,
you can take help from below link..
http://stackoverflow.com/questions/6458091/asp-net-mvc-dealing-with-radio-buttons-to-and-from-view-controller
Thanks
subhash
Subhash
Please, Mark as Answer if this reply helped you.
Mikesdotnett...
All-Star
154840 Points
19854 Posts
Moderator
MVP
Re: How do i write this particular condition in Razor C#?
Apr 21, 2012 06:57 AM|LINK
In Razor v1, you have to do something similar to your PHP approach:
This uses the shorthand C# conditional operator: http://msdn.microsoft.com/en-us/library/ty67wk28(v=vs.80).aspx
In v2 (which is in Beta), you use Conditional Attributes: http://mikepope.com/blog/DisplayBlog.aspx?permalink=2353
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
hubertjiang
0 Points
21 Posts
Re: How do i write this particular condition in Razor C#?
Apr 21, 2012 01:26 PM|LINK
sorry...but how do i check which version is my razor if i am using webmatrix 2 beta. Does this mean it is most like razor v2?? sorry for this noob question.
Mikesdotnett...
All-Star
154840 Points
19854 Posts
Moderator
MVP
Re: How do i write this particular condition in Razor C#?
Apr 21, 2012 05:33 PM|LINK
Then you are using Razor 2. Conditional attributes will work for you.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter