想要清除所有TextBox的文本值 [英] Want to Clear my text values of all TextBox
本文介绍了想要清除所有TextBox的文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello to all;
I am having 10 Textboxes and want to Clear my Text values from it, AVOIDING WRITING CODES FOR EACH TEXTBOX.
I know it can be done by casting. I have gone through internet.But dint got the required answer.
推荐答案
使用此功能
Use this Function
public void ClearTextBoxes(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
{
((TextBox)c).Clear();
}
if (c.HasChildren)
{
ClearTextBoxes(c);
}
}
}
您可以使用以下功能恢复控件
You can use following function to restore the control
public static void ResetControl(Page mypage)
{
Control myForm = mypage.FindControl("Form1");
foreach (Control ctrl in myForm.Controls)
{
//Clears TextBox
if (ctrl is System.Web.UI.WebControls.TextBox)
{
(ctrl as TextBox).Text = string.Empty;
}
//Clears DropDown Selection
if (ctrl is System.Web.UI.WebControls.DropDownList)
{
(ctrl as DropDownList).ClearSelection();
}
//Clears ListBox Selection
if (ctrl is System.Web.UI.WebControls.ListBox)
{
(ctrl as ListBox).ClearSelection();
}
//Clears CheckBox Selection
if (ctrl is System.Web.UI.WebControls.CheckBox)
{
(ctrl as CheckBox).Checked = false;
}
//Clears RadioButton Selection
if (ctrl is System.Web.UI.WebControls.RadioButtonList)
{
(ctrl as RadioButtonList).ClearSelection();
}
//Clears CheckBox Selection
if (ctrl is System.Web.UI.WebControls.CheckBoxList)
{
(ctrl as CheckBoxList).ClearSelection();
}
}
使用它让我知道... Thanx
Use it and let me know about it... Thanx
这篇关于想要清除所有TextBox的文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文