string mySelect = "";
//web控件
foreach (Control ct in form1.Controls)
{
if (ct.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
{
CheckBox cb = (CheckBox)ct;
if (cb.Checked == true)
{
if (mySelect == "")
{
mySelect += cb.Value;
}
else
{
mySelect += "~" + cb.Value;
}
}
}
}
//html控件
foreach (Control ct in form1.Controls)
{
if (ct.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox"))
{
HtmlInputCheckBox cb = (HtmlInputCheckBox)ct;
if (cb.Checked == true)
{
if (mySelect == "")
{
mySelect += cb.Value;
}
else
{
mySelect += "~" + cb.Value;
}
}
}
}
Page.RegisterStartupScript("alert", "<script language='javascript'> alert('" + mySelect + "!');</script>");