Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Another Checkbox Question

Reply
Thread Tools

Another Checkbox Question

 
 
The Corinthian
Guest
Posts: n/a
 
      10-13-2004
I am quite new to ASP scripting and seem to be haveing no success with
checkboxes at all.

I have a sql database with bit datatypes and I am trying to create a asp
webform which will display and update the data from checkboxes.

Any help would be appreciated.

Rob


 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      10-13-2004
What exactly are you having trouble with?

<input type="checkbox"<% If rs.fields.item(0).value = 1 Then response.write
" checked"%>>

Ray at work

"The Corinthian" <(E-Mail Removed)> wrote in message
news:ckj73c$e2b$(E-Mail Removed)...
>I am quite new to ASP scripting and seem to be haveing no success with
>checkboxes at all.
>
> I have a sql database with bit datatypes and I am trying to create a asp
> webform which will display and update the data from checkboxes.
>
> Any help would be appreciated.
>
> Rob
>



 
Reply With Quote
 
 
 
 
Rob
Guest
Posts: n/a
 
      10-13-2004
Hi,

I am probably mssing some thing I am creating my record set using the
following

data connection provided by inc file
<%
dim rs
dim strSQL




set rs=Server.CreateObject ("ADODB.Recordset")
strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
WHERE ID ='" & _
(Session("userid")) & "'"


Set rs = objConn.Execute (strSQL)



%>

using



<input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
response.write" checked"%>>



Returns
Error Type:
ADODB.Fields (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name
or ordinal.
/dbg12/prefs.asp, line 46



Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:(E-Mail Removed)...
> What exactly are you having trouble with?
>
> <input type="checkbox"<% If rs.fields.item(0).value = 1 Then
> response.write " checked"%>>
>
> Ray at work
>
> "The Corinthian" <(E-Mail Removed)> wrote in message
> news:ckj73c$e2b$(E-Mail Removed)...
>>I am quite new to ASP scripting and seem to be haveing no success with
>>checkboxes at all.
>>
>> I have a sql database with bit datatypes and I am trying to create a asp
>> webform which will display and update the data from checkboxes.
>>
>> Any help would be appreciated.
>>
>> Rob
>>

>
>



 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      10-13-2004
You've got it down just fine with just one small part. You forgot to put
"Arta" in quotes.

rs.Fields.Item("Arta").Value
''or alternatively
rs.Fields.Item(1).Value
'''Arta is the second column, so it has an index of 1. Column indexes start
at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2, Newsletter
is 3.

I suggest that you get in the habit of using Option Explicit at the top of
all your VBS-based ASP pages. If you had Option Explicit, the error would
have been "Variable is not defined - Arta" or something along those lines.

Ray at work

"Rob" <(E-Mail Removed)> wrote in message
news:1Adbd.111$(E-Mail Removed)...
> Hi,
>
> I am probably mssing some thing I am creating my record set using the
> following


> set rs=Server.CreateObject ("ADODB.Recordset")
> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
> WHERE ID ='" & _
> (Session("userid")) & "'"
>
>
> <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
> response.write" checked"%>>


> Returns
> Error Type:
> ADODB.Fields (0x800A0CC1)
> Item cannot be found in the collection corresponding to the requested name
> or ordinal.
> /dbg12/prefs.asp, line 46



 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      10-13-2004
Ah sorted - thank you very very much


"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:e49Z$(E-Mail Removed)...
> You've got it down just fine with just one small part. You forgot to put
> "Arta" in quotes.
>
> rs.Fields.Item("Arta").Value
> ''or alternatively
> rs.Fields.Item(1).Value
> '''Arta is the second column, so it has an index of 1. Column indexes
> start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
> Newsletter is 3.
>
> I suggest that you get in the habit of using Option Explicit at the top of
> all your VBS-based ASP pages. If you had Option Explicit, the error would
> have been "Variable is not defined - Arta" or something along those lines.
>
> Ray at work
>
> "Rob" <(E-Mail Removed)> wrote in message
> news:1Adbd.111$(E-Mail Removed)...
>> Hi,
>>
>> I am probably mssing some thing I am creating my record set using the
>> following

>
>> set rs=Server.CreateObject ("ADODB.Recordset")
>> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
>> WHERE ID ='" & _
>> (Session("userid")) & "'"
>>
>>
>> <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
>> response.write" checked"%>>

>
>> Returns
>> Error Type:
>> ADODB.Fields (0x800A0CC1)
>> Item cannot be found in the collection corresponding to the requested
>> name or ordinal.
>> /dbg12/prefs.asp, line 46

>
>



 
Reply With Quote
 
The Corinthian
Guest
Posts: n/a
 
      10-14-2004
I was a bit hasty there - the returning the values is fine now, but now I am
trying to update them.

using

strSQL = "UPDATE preferences SET"
strSQL = strSQL & "Arta Request.Form("Arta") & "'"
strSQL = strSQL & " WHERE ID = Session("UserID")"

but off course the value "ON" wont go into the bit field, how would I
convert it so it compatitble.

Many thanks again.

Rob
"Rob" <(E-Mail Removed)> wrote in message
news:yZdbd.1462$(E-Mail Removed)...
> Ah sorted - thank you very very much
>
>
> "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
> message news:e49Z$(E-Mail Removed)...
>> You've got it down just fine with just one small part. You forgot to put
>> "Arta" in quotes.
>>
>> rs.Fields.Item("Arta").Value
>> ''or alternatively
>> rs.Fields.Item(1).Value
>> '''Arta is the second column, so it has an index of 1. Column indexes
>> start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
>> Newsletter is 3.
>>
>> I suggest that you get in the habit of using Option Explicit at the top
>> of all your VBS-based ASP pages. If you had Option Explicit, the error
>> would have been "Variable is not defined - Arta" or something along those
>> lines.
>>
>> Ray at work
>>
>> "Rob" <(E-Mail Removed)> wrote in message
>> news:1Adbd.111$(E-Mail Removed)...
>>> Hi,
>>>
>>> I am probably mssing some thing I am creating my record set using the
>>> following

>>
>>> set rs=Server.CreateObject ("ADODB.Recordset")
>>> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
>>> WHERE ID ='" & _
>>> (Session("userid")) & "'"
>>>
>>>
>>> <input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
>>> response.write" checked"%>>

>>
>>> Returns
>>> Error Type:
>>> ADODB.Fields (0x800A0CC1)
>>> Item cannot be found in the collection corresponding to the requested
>>> name or ordinal.
>>> /dbg12/prefs.asp, line 46

>>
>>

>
>



 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      10-14-2004
Give the checkbox a value of 1. Also, you have code enclosed in quotes
below.

<input name="chkArta" type="checkbox" value="1"<% If
CBool(rs.Fields.Item(1).Value) Then Response.Write " checked"%>>

And then in code:

<%
Dim iArta
iArta = Abs(CBool(Request.Form("chkArta")))
strSQL = "UPDATE preferences SET YourColumnNameHere = " & iArta & " WHERE
[ID] = " & Session("UserID")
RESPONSE.WRITE STRSQL
RESPONSE.END
%>

Ray at work



"The Corinthian" <(E-Mail Removed)> wrote in message
news:ckld7r$g06$(E-Mail Removed)...
>I was a bit hasty there - the returning the values is fine now, but now I
>am trying to update them.
>
> using
>
> strSQL = "UPDATE preferences SET"
> strSQL = strSQL & "Arta Request.Form("Arta") & "'"
> strSQL = strSQL & " WHERE ID = Session("UserID")"
>
> but off course the value "ON" wont go into the bit field, how would I
> convert it so it compatitble.



 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      10-14-2004
Many thanks yet again, I was nearly there, but didn't set a value nor did I
know about CBool.

Cheers again.

Rob

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:%23jAf$(E-Mail Removed)...
> Give the checkbox a value of 1. Also, you have code enclosed in quotes
> below.
>
> <input name="chkArta" type="checkbox" value="1"<% If
> CBool(rs.Fields.Item(1).Value) Then Response.Write " checked"%>>
>
> And then in code:
>
> <%
> Dim iArta
> iArta = Abs(CBool(Request.Form("chkArta")))
> strSQL = "UPDATE preferences SET YourColumnNameHere = " & iArta & " WHERE
> [ID] = " & Session("UserID")
> RESPONSE.WRITE STRSQL
> RESPONSE.END
> %>
>
> Ray at work
>
>
>
> "The Corinthian" <(E-Mail Removed)> wrote in message
> news:ckld7r$g06$(E-Mail Removed)...
>>I was a bit hasty there - the returning the values is fine now, but now I
>>am trying to update them.
>>
>> using
>>
>> strSQL = "UPDATE preferences SET"
>> strSQL = strSQL & "Arta Request.Form("Arta") & "'"
>> strSQL = strSQL & " WHERE ID = Session("UserID")"
>>
>> but off course the value "ON" wont go into the bit field, how would
>> I convert it so it compatitble.

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPNET CheckBox and a CheckBox in a TemplateField Jason Huang ASP .Net 0 06-29-2007 12:35 AM
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
disable checkbox list checkbox Vikram ASP .Net 1 01-25-2006 02:59 PM
Text on Checkbox below the checkbox tshad ASP .Net 0 04-14-2005 11:26 PM
checkbox onclick check another checkbox Terje Javascript 5 11-18-2004 11:57 PM



Advertisments