CheckBox Outside DataList & Labels Inside DataList

  • Thread starter Thread starter rn5a
  • Start date Start date
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.
 
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
 
Back
Top