I have 8 checkboxes.
On the page load event I want to write the code such that
if the value in the database is "Submitted" the checkbox will appear checked.
If the value is "Not Submitted" it will appear unchecked.
-
1Have you tried anything?Igoy– Igoy2013-02-12 05:36:23 +00:00Commented Feb 12, 2013 at 5:36
-
Show us what you've tried already..Andy Refuerzo– Andy Refuerzo2013-02-12 05:36:59 +00:00Commented Feb 12, 2013 at 5:36
-
check the posted answer or show us your code what you had tried?nrsharma– nrsharma2013-02-12 05:43:48 +00:00Commented Feb 12, 2013 at 5:43
Add a comment
|
3 Answers
You can check the values like this
if(!Page.IsPostBack)
{
if(dbvalue=="Submitted")
{
chk1.checked=true;
chk2.checked=true;
chk3.checked=true;
chk4.checked=true;
chk5.checked=true;
chk6.checked=true;
chk7.checked=true;
chk8.checked=true;
}
else if(dbvalue=="Not Submitted")
{
chk1.checked=false;
chk2.checked=false;
chk3.checked=false;
chk4.checked=false;
chk5.checked=false;
chk6.checked=false;
chk7.checked=false;
chk8.checked=false;
}
}
Comments
If don't want to do anything in the code-behind, a faster and easy method would be to create a new column of data type bit on the select query and then just bind the checkbox to that. 0 = false and 1 = true. Example would be:
SELECT
CAST((CASE WHEN SubmitColumn = 'Submitted' THEN
1
ELSE
0
END) AS BIT) AS chkValue
FROM Table_1