Friday, February 6, 2009

How to clear the controls using VB.Net?

Sub ClearControls(ByVal parent As Control)
For Each ChildControl As Control In parent.Controls
If (ChildControl.Controls.Count > 0) Then
ClearControls(ChildControl)
Else
If TypeOf ChildControl Is TextBox Then
DirectCast(ChildControl, TextBox).Text = String.Empty
ElseIf TypeOf ChildControl Is DropDownList Then
DirectCast(ChildControl, DropDownList).SelectedIndex = 0
ElseIf TypeOf ChildControl Is CheckBox Then
DirectCast(ChildControl, CheckBox).Checked = False
End If
End If
Next
End Sub

No comments:

 
Feedback Form