ASP.NET with C# and SQL SERVER , some vb.net . asp.net examples, asp.net codes, asp.net programs, c# code, sql server queries, important codes.
Friday, 19 October 2012
clear all controls of a form with foreach loop in asp.net with c#
clear(Page);
private void clear(Control sender)
{
TextBox txt;
DropDownList ddl;
RadioButtonList rdb;
foreach (Control cnt in sender.Controls)
{
if (cnt is TextBox)
{
txt = (TextBox)cnt;
txt.Text = "";
}
else if (cnt is DropDownList)
{
ddl = (DropDownList)cnt;
ddl.SelectedIndex = 0;
}
else if (cnt is RadioButtonList)
{
rdb = (RadioButtonList)cnt;
rdb.SelectedIndex = 0;
}
if (cnt.HasControls())
{
clear(cnt);
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment