Checkbox Value - Please help

A

Amy Snyder

For what I thought would be a very simple task is turning out to be very
frustrating. I have been trying for a day now to extract checkbox
values from my form and nothing is working.

On my form load I am setting the values of my checkboxes:
chk1.Attributes.Add("checkValue", "151010")
chk2.Attributes.Add("checkValue", "151020")
chk3.Attributes.Add("checkValue", "151030")
chk4.Attributes.Add("checkValue", "151040")
chk5.Attributes.Add("checkValue", "151050")
...

When the submit button is clicked, I want to loop through all checkboxes
and retrieve the value of the checkboxes that were selected.


Dim ctrl As New Control
Dim chk As New CheckBox
Dim strIndustry As String

' Loop through all the controls on the panel.
' Create the string for the SQL statement.
For Each ctrl In pnlSearchResults.Controls
If TypeOf ctrl Is CheckBox Then
' Get value of checkbox
End If
Next

I have tried a few different ways and keep getting errors. Could
someone please provide a solution? Thanks!
 
C

Claudio Perrone

Hi there,
Here is what you need.

' assuming page tracing is enabled...

For Each ctrl In pnlSearchResults.Controls
If TypeOf ctrl Is CheckBox Then
chk = CType(ctrl, CheckBox)
If chk.Checked Then
Trace.Warn(chk.Attributes("checkValue"))
End If
End If
Next

Regards
Claudio
 
V

Vannela

I want to get the checkbox status from the datalist web
control when checkbox is placed int the item template of
the datalist.

How can i achieve that?
I have used findcontrol method but it did not help me what
is the other alternate?

Thank you

-----Original Message-----
Hi there,
Here is what you need.

' assuming page tracing is enabled...

For Each ctrl In pnlSearchResults.Controls
If TypeOf ctrl Is CheckBox Then
chk = CType(ctrl, CheckBox)
If chk.Checked Then
Trace.Warn(chk.Attributes("checkValue"))
End If
End If
Next

Regards
Claudio

Amy Snyder said:
For what I thought would be a very simple task is turning out to be very
frustrating. I have been trying for a day now to extract checkbox
values from my form and nothing is working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top