ClearText
private void Cleartxt()
{
foreach (Control cntrol in EnumerateControlsRecursive(Page))
{
if (cntrol is TextBox)
{
TextBox txt = (TextBox)cntrol;
txt.Text = string.Empty;
}
else if (cntrol is DropDownList)
{
DropDownList ddl = (DropDownList)cntrol;
ddl.SelectedIndex = 0;
}
}
}
/// <summary>
/// Recursive function for get controls
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
{
foreach (Control cntrol in EnumerateControlsRecursive(Page))
{
if (cntrol is TextBox)
{
TextBox txt = (TextBox)cntrol;
txt.Text = string.Empty;
}
else if (cntrol is DropDownList)
{
DropDownList ddl = (DropDownList)cntrol;
ddl.SelectedIndex = 0;
}
}
}
/// <summary>
/// Recursive function for get controls
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
0 comments:
Post a Comment