C#:
------
public void ResetFormControlValues(this) 'or'
public void ResetFormControlValues(Control parent)
{
foreach (Control c in parent.Controls)
{
if (c.Controls.Count > 0)
{
ResetFormControlValues(c);
}
else
{
switch (c.GetType().ToString())
{
case "System.Web.UI.WebControls.TextBox":
((TextBox)c).Text = "";
break;
case "System.Web.UI.WebControls.CheckBox":
((CheckBox)c).Checked = false;
break;
case "System.Web.UI.WebControls.RadioButton":
((RadioButton)c).Checked = false;
break;
}
}
}
------------------------------------------------------
VB.Net
----------
Public Sub ResetFormControlValues(ByVal parent As Control)
'Dim c As New Control
For Each c As Control In parent.Controls
If c.Controls.Count > 0 Then
ResetFormControlValues(c)
Else
Select Case (c.GetType().ToString())
Case "System.Web.UI.WebControls.TextBox"
CType(c, TextBox).Text = ""
Case "System.Web.UI.WebControls.CheckBox"
CType(c, CheckBox).Checked = False
Case "System.Web.UI.WebControls.RadioButton"
CType(c, RadioButton).Checked = False
Case "System.Web.UI.WebControls.DropDownList"
CType(c, DropDownList).SelectedIndex = 0
End Select
End If
Next
End Sub
Monday, October 26, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment