CheckBox Outside DataList & Labels Inside DataList

R

rn5a

A ASPX page has a DataList control with a few Labels. This page also
has a CheckBox which resides OUTSIDE the DataList. By default, this
CheckBox is checked. If the CheckBox is checked, then the Labels
existing in the DataList should be visible but if the CheckBox is
unchecked by the user, the Labels inside the DataList should be made
invisible.

How do I do this?

Note that the AutoPostBack property of the CheckBox has been set to
True so that as soon as the CheckBox is checked/unchecked by the user,
the page gets posted & the Labels inside the DataList become
visible/invisible respectively.
 
R

rn5a

I figured it out; this is how I did it (just in case if someone else
happens to come across this dilemma....on the CheckedChanged event of
the CheckBox whose ID is "chk1"):

Sub chk1_CheckChanged(ByVal obj As Object, ByVal ea As EventArgs)
Dim dlItem As DataListItem

For Each dlItem In DataList1.Items
If (chk1.Checked) Then
dlItem.FindControl("Label1").Visible = True
dlItem.FindControl("Label2").Visible = True
dlItem.FindControl("Label3").Visible = True
Else
dlItem.FindControl("Label1").Visible = False
dlItem.FindControl("Label2").Visible = False
dlItem.FindControl("Label3").Visible = False
End If
Next
End Sub
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top