我在前台有
<asp:Panel ID="CommodityType" runat="server" CssClass="comtype" >
</asp:Panel>
后台动态添加控件
DataSet xmlcomtype = new DataSet();
xmlcomtype.ReadXml(Server.MapPath(@"~/XML/CommodityType.xml"));
foreach(DataRow drtype in xmlcomtype.Tables[0].Rows)
{
CheckBox cb = new CheckBox();
cb.Text = drtype["Type"].ToString();
CommodityType.Controls.Add(cb);
}
后台遍历控件
foreach (Control c in CommodityType.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
{
CheckBox cb = (CheckBox)c;
if (cb.Checked)
ct.CommodityType += "," + cb.Text;
}
}
if (!string.IsNullOrEmpty(ct.CommodityType))
ct.CommodityType = ct.CommodityType.Substring(1);
怎么我遍历不出控件的,输出控件数量
ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('" + CommodityType .Controls.Count.ToString()+ "');</script>");
输出值为1
但是我后台添加了好几个控件了
求帮忙
人到中年有点甜