To reset or clear all the values in the Controls just place the following method in the codebehind file i.e) .cs file and call the method "ResetFormControlValues" to clear data in the controls.
private 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;
case "System.Web.UI.WebControls.ListBox":
((ListBox)c).SelectedValue = null;
break;
case "System.Web.UI.WebControls.DropDownList":
((DropDownList)c).SelectedValue = null;
break;
}
}
}
}
Thursday, September 3, 2009
Clear all the values in the Controls
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment