|
Find a control in masterpage (contentplaceholder)
|
|
11.01.2008 11:30:36
- Filed under :
Asp.net
|
|
|
// to call :
CheckCheckBoxes(Page);
// function :
private string CheckCheckBoxes(Control oControl)
{
string str = string.Empty;
foreach (Control c in oControl.Controls)
{
if (c is CheckBox)
{
CheckBox chk = (CheckBox)c.FindControl(c.ID);
if (chk.Checked)
{
str += chk.ID;
}
}
if (c.HasControls())
{
CheckCheckBoxes(c);
}
}
return str;
}
Keywords : Loop in controls.
|
with
1
comments
|
|
says ;
23.02.2008 15:39:45
hi guy. That is very good algorithm but very old :)
this is my algorithm :) this very nice.
List<Control> ctrlList = new List<Control>(); private void GetItems<T>(Control control, Func<T, bool> func) where T : Control { foreach (Control c in control.Controls) { if (c is T) { if (func((T)c)) { ctrlList.Add(c); } }
if (c.HasControls()) { GetItems<T>(c, func); } } }
if you want to call all checked checkbox. your code look like
GetItems<CheckBox>(Page, (CheckBox c) => c.Checked );
i love Lambda and generic. :D
|