Karatas, FERHAT
I would love to change the world, but they won't give me the source code!
Find a control in masterpage (contentplaceholder)
11.1.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

Oğuz Kurumlu says ;
23.2.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
What do you think ?
Security Code 2190
Check S. Code
Name  
Email  
Home Page  
Comments