?
Solved

Bind data to checkbox

Posted on 2006-04-02
8
Medium Priority
?
293 Views
Last Modified: 2010-04-25
Classic ASP, VBScript and Access database

I am creating an 'Edit Item' page, and I now want to bind ItemYesNo value to a checkbox, so that checkbox displays correct value stored in db.

Here's what I have so far....

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="<%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>
">

but it doesn't work. Help
0
Comment
Question by:Swn-Y-Mor
8 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 16353865
do something like this

Try this


<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="Yes" <%If CStr(rsItem("ItemYesNo")) = "1" Then Response.Write "checked"%>>



hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 16353870
Then in your processing page,

<%
If Request("ItemYesNo") = "Yes" Then
    ' checked
Else
   ' not checked
End If
%>
0
 

Author Comment

by:Swn-Y-Mor
ID: 16354007
Sorry, not too sure what you mean by processing page.
I only have the one page, that has a form (using the 'post' method) and uses a standard DW Update records behaviour.
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
LVL 33

Expert Comment

by:hongjun
ID: 16354030
Then ignore my http:#16353870
0
 

Author Comment

by:Swn-Y-Mor
ID: 16355346
Hey Hongjun,
Don't give up on me now!
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16358251
Swn-Y-Mor, you are nearly there on your attempt.  The problem is that you are trying to set the VALUE property of the checkbox, where actually you need to set the CHECKED property based on your database value.

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" checked="<%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>">
0
 
LVL 33

Expert Comment

by:hongjun
ID: 16360142
Post more code.
0
 
LVL 9

Accepted Solution

by:
smaccari earned 2000 total points
ID: 16368313
Just reposting the answer made on ASP channel:

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="True" <%If (CStr(rsItem.Fields.Item("ItemYesNo").Value) = CStr("True")) Then Response.Write("checked")%>>

The db field had a value of True/False though.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question