how to check whether checkbox is checked or not

Posted by Oswaldlily under ASP.NET on 1/5/2012 | Points: 10 | Views : 5620 | Status : [Member] | Replies : 2
function1name(a,b, c,d, Int(ChkPrice.Checked), z)

a,b,c,d,z are strings
whiling calling a function i need to check checkbox is checked or not
so In VB,have used like Int(ChkPrice.Checked) .this ll return 0/1

in C# how to use ?

i tried lik convert.ToInt32(ChkPrice.checked) but error still




Responses

Posted by: Manchik.83 on: 1/5/2012 [Member] Starter | Points: 25

Up
0
Down
If you are using javascript then,
get the id of checkbox by document.getElementByID("CheckBoxID") and assign it to var chk as
var chk=document.getElementByID("CheckBoxID") ;
Now,chk.checked will return boolean as true /false.If checked then chk.checked will return true otherwise it will return false.


In C Sharp,
declare the Checkbox ID as protected Checkbox CheckboxID; This ID should be same as ID used in the page.
then bool status=CheckBoxID.Checked will return true if it is checked else it will return false.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manchik.83 on: 1/5/2012 [Member] Starter | Points: 25

Up
0
Down
Little extension in above answer
In C sharp CheckBoxID is the object of CheckBox class so create the object first using new operator in page load method.
Then assign the property of checkbox control used in business layer to the CheckBoxID.Checked.The property contains the information from connected database whether the CheckBox attribute i true or false.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response