In most of the web applications you may need to add a reset button to clear the values of a form which is having dropdown and textboxes, in this situation most of the developers are doing this by adding code like TextBox1.Text =""; and DropDown1.SelectedValue="0", there is a simple solution to do this.
See below code:
//Function to reset controls public static void ResetFormControls(ControlCollection pagecontrols, bool txtbox, bool dropdownlist, bool label) { //Loop to find page control foreach (Control cntrl in pagecontrols) { foreach (Control mycontrols in cntrl.Controls) { //Checking whether the control is a textbox if (txtbox) { if (mycontrols is TextBox) { { (mycontrols as TextBox).Text = string.Empty; } } //Checking it is a drop down list or not if (dropdownlist) { if (mycontrols is DropDownList) { (mycontrols as DropDownList).SelectedIndex = 0; } } //checking it is a label or not if (label) { if (mycontrols is Label) { (mycontrols as Label).Text = string.Empty; } } } } }
|
| Author: venkatesan 12 Nov 2009 | Member Level: Diamond Points : 1 |
Its seems this Resource is Duplicate.
Posting the same Resource as two times.
Pls Avoid this.
|
| Author: Prajeesh 12 Nov 2009 | Member Level: Gold Points : 0 |
Hi venkatesen, It is occurred accidentally when i modified the resource.
|