因此,我从表单中接收了一些回发数据,并且需要获取父控件中一组复选框的复选框值。我对其进行了编码,它正在工作,但现在不再工作,我不知道为什么。复选框是在页面加载时动态创建的,但在回发时,当表单已检查项目时似乎没有检查任何内容,唯一的回发事件是提交按钮事件。
// This is from the btnSubmit Postback event that isn't working anymore
foreach (CheckBox cb in ShowPermissions.Controls.OfType<CheckBox>())
{
if (cb.Checked)
{
// Add New Admins Permissions
Permission p = new Permission();
p.AdminUserID = au.id;
p.AdminMenuID = Convert.ToInt32(cb.ID.ToString().Substring(4));
ngdb.Permissions.InsertOnSubmit(p);
submitResult.InnerHtml += cb.ID.ToString();
// Does not run now?
}
// can see the checkbox object
}
protected void Page_Load(object sender, EventArgs e)
{
FunctionType = Request.QueryString["func"] != null && Request.QueryString["func"] != "" ? Request.QueryString["func"] : null;
RID = Request.QueryString["rid"] != null && Request.QueryString["rid"] != "" ? int.Parse(Request.QueryString["rid"]) : -1;
PopulateAdminTypes();
if (!IsPostBack && FunctionType == "edit" && RID != -1)
{
// Populate User details for Edit
PopulateUser(RID);
// Populate checkboxes and check selected options
PopulateAdminPermissionOptions(true, RID);
// Disable password change
ChangePassword(false);
}
else if (!IsPostBack)
{
chkChangePassword.Visible = false;
PopulateAdminPermissionOptions(false, -1);
}
}
private void PopulateAdminPermissionOptions(bool blnPopulateForEdit, int RID)
{
// Get Logged in Admin ID
int intAdminId = Convert.ToInt32(Session["AdminID"]);
int intAdminTypeId = Convert.ToInt32(Session["AdminTypeID"]);
using (NewGeorgeDataContext ngdb = new NewGeorgeDataContext())
{
var am = ngdb.AdminMenus.AsQueryable();
// Hide Add and Edit Options from Non Super Users
var amUsers = ngdb.AdminMenus.Where(x => x.id > 2 && x.id < 5);
if (intAdminTypeId > 1) am = am.Except(amUsers);
foreach (var m in am.OrderBy(x => x.MenuTypeID).ThenBy(x => x.id))
{
// Add New CheckBox
CheckBox cb = new CheckBox();
cb.ID = "chk_" + m.id;
cb.CssClass = "chkItems";
cb.Text = m.AdminMenuType.Name + ": " + m.Name;
// Get Admin Permission objects
if (blnPopulateForEdit)
{
var ap = ngdb.Permissions.SingleOrDefault(x => x.AdminUserID == RID && x.AdminMenuID == m.id);
if (ap != null)
{
cb.Checked = true;
}
}
ShowPermissions.Controls.Add(new LiteralControl("<p>"));
ShowPermissions.Controls.Add(cb);
ShowPermissions.Controls.Add(new LiteralControl("</p>"));
}
}
}
有人可以锻炼我看不到的atm吗?