动态绑定控件与查找

无法获得控件说明是母版页与内容页事件顺序问题。div.Controls.Add(ck);之后去查找应该是可以找到的

 

aspx:

<div id="DIVcheck" runat="server">
</div>

CS:

 

protected void CheckDataBind()
{
            DataSet ds = ActionBLL.GetAllList();
            DataSet dsList = ActionGroupBLL.GetRoleAuthorityList(group_id);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                CheckBox ck = new CheckBox();
                HtmlGenericControl div = new HtmlGenericControl("div");
                DIVcheck.Controls.Add(div);
                ck.Text = dr["action_name"].ToString();
                ck.ID = dr["action_id"].ToString();
                div.Style.Value = "float:left;width:150px";
                div.Controls.Add(ck);
                foreach (DataRow drList in dsList.Tables[0].Rows)
                {
                    if (drList["action_id"].ToString().Equals(ck.ID))
                    {
                        ck.Checked = true;
                    }
                }
            }
      ds.Dispose();
}
posted @ 2012-06-05 18:23  Setme  阅读(191)  评论(0编辑  收藏  举报