"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, May 7, 2010

Clear All Fields in Asp.net C#

  Hi, 2day i'm showing a small piece of code that can b very useful through our Project.
Does u ever feel boring when u try clear all field in web-page.V can simply avoid that by using a one time effort
here i created a function u call the when ever u need.

Function


public static void ClearFields(ControlCollection pageControls)
{
foreach (Control contl in pageControls)
{
string strCntName = (contl.GetType()).Name;
switch (strCntName)
{
case "TextBox":
TextBox tbSource = (TextBox)contl;
tbSource.Text = "";
break;
case "RadioButtonList":
RadioButtonList rblSource = (RadioButtonList)contl;
rblSource.SelectedIndex = -1;
break;
case "DropDownList":
DropDownList ddlSource = (DropDownList)contl;
ddlSource.SelectedIndex = -1;
break;
case "ListBox":
ListBox lbsource = (ListBox)contl;
lbsource.SelectedIndex = -1;
break;
}
ClearFields(contl.Controls);
}
}

Call the function 


Now i will give u small documentaion how it workz. It will find all the textbox, Radiobutton list,Dropdown, Listbox On the webpage 'n make to default postion.
Hope It help u some ways

Have a nice day... 'N happy Coding :)

Drive Me CrazyBuffy the Vampire Slayer: Movie/Drive Me CrazyDrive Me Crazy [VHS]

No comments: