Due to the closure of the project, I have recently been busy doing some optimization of methods to organize some share for everyone.
When there are many controls in the page, we need to clear the value of the time, it is too troublesome to empty. So you write a method that lets you customize the type of empty controls and respond flexibly to your business needs.
Copy Code code as follows:
<summary> Reset method control type enumeration </summary>
<remarks> knowledge Domain http://www.qqextra.com 2012-12-28</remarks>
public enum Resettype
{
<summary>
Textbox
</summary>
Txt
<summary>
DropDownList
</summary>
Ddl
<summary>
RadioButtonList
</summary>
Rbl
<summary>
All Resettype types
</summary>
All
}
<summary> Reset control's value </summary>
<remarks> knowledge Domain http://www.qqextra.com 2012-12-28</remarks>
<param name= "Control" >this</param>
<param name= "rst" >resettype.all to empty all control types contained in the Resettype enumeration </param>
public static void ReSet (control control, params resettype[] rst)
{
BOOL Bltxt = false;
BOOL Blddl = false;
BOOL BLRBL = false;
foreach (Resettype type in rst)
{
if (type = = Resettype.all)
{
Bltxt = true;
Blddl = true;
BLRBL = true;
Break
}
Else
if (type = = ReSetType.TXT)
Bltxt = true;
else if (type = = RESETTYPE.DDL)
Blddl = true;
else if (type = = RESETTYPE.RBL)
BLRBL = true;
}
foreach (Control C-control. Controls)
{
text box
if (c is TextBox && bltxt = = True)
{
((TextBox) c). Text = "";
}
Else
Drop down list
if (c is DropDownList && blddl = = True)
{
DropDownList DDL = (DropDownList) C;
if (DDL. Items.Count > 0)
{
Ddl. SelectedIndex = 0;
}
}
Else
radio button List
if (c is radiobuttonlist && BLRBL = = True)
{
((RadioButtonList) c). SelectedIndex =-1;
}
Else
if (C.hascontrols ())
{
Recursion
ReSet (c, RST);
}
}
}