I thought this would work. But it's not wor开发者_如何学Cking. It's never getting inside of if (c is HtmlInputCheckBox)
private string GetAllCheckBoxes(ControlCollection controls)
{
StringBuilder sb = new StringBuilder();
foreach (Control c in controls)
{
if (c.HasControls())
{
GetAllCheckBoxes(c.Controls);
}
else
{
if (c is HtmlInputCheckBox)
{
CheckBox cb = c as CheckBox;
if (cb.Checked)
{
sb.Append(cb.ID + "_1");
}
else
{
sb.Append(cb.ID + "_0");
}
}
}
}
return sb.ToString();
}
update: c is throwing somesort of error.
Parent = {InnerText = '((System.Web.UI.HtmlControls.HtmlContainerControl)(((System.Web.UI.HtmlControls.HtmlGenericControl)(c.Parent)))).InnerText' threw an exception of type 'System.Web.HttpException'}
HtmlInputCheckBox
and CheckBox
are different classes and do not inherit from the other. An is
test on one won't work for the other and vice versa. Sounds like the control is probably an instance of a CheckBox
so change the conditional to:
if (c is CheckBox)
精彩评论