I have a checklist box with one value in it, and depending if that box is checked or not, I want to output a string. How could I check if the box is checked or not... in .NET or XSLT doesn't matter.
I created an Umbraco Datatype from the Dev Section of type checkbox list with one value, and then assigned that type to a property on my doctype. Nothing custom just all Umbraco here. I know how to check if a checkbox is checked the general .NET way just don't know if same rules apply here.
Are you running this check from the backend or the website and where are you wanting to display this string?
If from the backend, you could get it's value with the Document API - the I think the property value should be empty if unchecked
Document d = new Document(Convert.ToInt32(HttpContext.Current.Request["id"])); if (d.getProperty("aliasofcheckboxproperty") != null && !String.IsNullOrEmpty(d.getProperty("aliasofcheckboxproperty").Value.ToString())) { //write out your string... }
Or from the website you could of course use XSLT
<xsl:if test="string($currentPage/aliasofcheckboxproperty) != ''"> write out your string </xsl:if>
Also would it be easier to use a True/false (single checkbox) field or is there a reason you are using a CheckboxList?
How to Check if Checkbox list value is checked
I have a checklist box with one value in it, and depending if that box is checked or not, I want to output a string. How could I check if the box is checked or not... in .NET or XSLT doesn't matter.
Hi Kevon,
Could you give us a bit more info?
Is the checkbox on the website or the back end? Assuming website since you mentioned XSLT.
How are you rendering the checkbox?
Is the checkbox inside a form that you are posting?
If so, you can use XSLT with the umbraco.library helper to query the Request collection, something like:
If you are not posting the form you might need to use some jQuery, something along the lines of:
-Tom
Thanks Tom,
I created an Umbraco Datatype from the Dev Section of type checkbox list with one value, and then assigned that type to a property on my doctype. Nothing custom just all Umbraco here. I know how to check if a checkbox is checked the general .NET way just don't know if same rules apply here.
Are you running this check from the backend or the website and where are you wanting to display this string?
If from the backend, you could get it's value with the Document API - the I think the property value should be empty if unchecked
Or from the website you could of course use XSLT
Also would it be easier to use a True/false (single checkbox) field or is there a reason you are using a CheckboxList?
-Tom
Thanks Tom,
For some reason I just thought it would be a different process because the datatype was a checkbox.
is working on a reply...