How do I have all controls on the specified page under the ASP.NET [Original]

xiaoxiao2021-03-06  48

How to specify all controls on the specified page over the ASP.NET

Order: The purpose of writing it is that this code will help some friends!

#Region Clear all control content on the specified page, public static void clearllcontent ()

///

/// Clear all the control content on the specified page, including TextBox, Checkbox, CheckBoxList, Radiobutton, RadiobuttonList. But unclear

// / Dally, in addition to ListBox, DropdownList, because such control values ​​can be used for current pages, generally these controls are dictionary data.

/// Author: Kevin

/// Date: 2004-12-02

///

/// Specified page

Public static void clearllcontent (System.Web.ui.Control Page)

{

Int nPageControls = page.controls.count;

For (int i = 0; i

{

Foreach (System.Web.ui.Control Control in page.controls [i] .controls)

{

IF (Control.hasControls ())

{

CLEARALLTEXT (Control);

}

Else

{

IF (Control Is Textbox)

Control as textbox .Text = "";

IF (Control Is Checkbox)

Control as checkbox .Checked = false;

IF (Control Is RadiobuttonList)

Control as radiobuttonlist .selectedIndex = -1;

IF (Control Is Radiobutton)

Control as radiobutton .Checked = false;

IF (Control Is CheckboxList)

{

Foreach (ListItem Item in (Control as CheckBoxList) .Items

{

Item.selected = false;

}

}

} // if..else

} // foreach

} // for

}

#ndregion

转载请注明原文地址:https://www.9cbs.com/read-80308.html

New Post(0)