Due to the end of the project, I have been busy optimizing some methods and made some suggestions for you.
When there are many controls in the page, it is too troublesome to clear their values one by one. So I wrote this method to customize the type of the clear control and flexibly respond to business needs.
Copy codeThe Code is as follows:
/// <Summary> Reset method control type enumeration </summary>
/// <Remarks> knowledge domain http://www.qqextra.com </remarks>
Public enum ReSetType
{
/// <Summary>
/// TextBox
/// </Summary>
TXT,
/// <Summary>
/// DropDownList
/// </Summary>
DDL,
/// <Summary>
/// RadioButtonList
/// </Summary>
RBL,
/// <Summary>
/// All ReSetType types
/// </Summary>
ALL
}
/// <Summary> Reset the control value </summary>
/// <Remarks> knowledge domain http://www.qqextra.com </remarks>
/// <Param name = "control"> this </param>
/// <Param name = "rst"> ReSetType. ALL indicates clearing 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 in 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
// List of radio buttons
If (c is RadioButtonList & blRbl = true)
{
(RadioButtonList) c). SelectedIndex =-1;
}
Else
If (c. HasControls ())
{
// Recursion
ReSet (c, rst );
}
}
}