About Me

My photo
a Dynamic and Energetic guy.....

Sunday, March 8, 2009

How to find selected checkbox controls inside Webpage

using System.Collections.Generic;

protected void StoreSelectedDates()
{
Control[] allControls = FlattenHierachy(Page);

foreach (Control control in allControls)
{
CheckBox mycheckBox = control as CheckBox;
if (mycheckBox != null)
{
if (mycheckBox.Checked)
{
try
{
string setDay = mycheckBox.ID.Substring(3);
}
catch (Exception ex)
{}
}
}
}


private Control[] FlattenHierachy(Control root)

{
List list = new List();
list.Add(root);
if (root.HasControls())
{
foreach (Control control in root.Controls)
{
list.AddRange(FlattenHierachy(control));
}
}
return list.ToArray();
}



No comments:

My Masters