what it wrong with this code

G

Guest

I going through all the checkboxes in my datalist to get the value (checked
or not checked) and it keeps returning false even if its checked.

Dim I As Long
For I = 0 To datalist.Items.Count - 1
Dim CurrentCheckBox As CheckBox
CurrentCheckBox = datalist.Items(I).FindControl("checkbox")
Response.Write("Item(" & I & "): " &
CurrentCheckBox.Checked.ToString() & "<br>")
'Response.Redirect("webform1.aspx?I=" & I & "&value=" &
CurrentCheckBox.Checked.ToString() & "|")
Next
 
G

Guest

It seems to be that since each control has to have a unique name that this
wouldn't find but one checkbox control - the one named "checkbox". I would
loop through the controls in the datalist determine if the current control is
a checkbox then verify if it's checked or not. This syntax probably isn't
right but you should get the idea.

Dim obj as Object
foreach obj in Datalist.Controls
if obj.GetType = "checkbox" then
if CType(obj, checkbox).Checked Then
'do something
End If
end if
next
 

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,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top