C# 动态加载后实现DataList复选框全选反选功能?
后台代码://全选及取消protectedvoidcbAll_CheckedChanged(objectsender,EventArgse){//CheckBoxall=...
后台代码:
//全选及取消 protected void cbAll_CheckedChanged(object sender, EventArgs e)
{
//CheckBox all = sender as CheckBox;
System.Web.UI.WebControls.CheckBox chkStu;
foreach (DataListItem ctl in ddlInfo.Items)
{
if (CheckBox11 is CheckBox)
{
CheckBox chk = CheckBox11 as CheckBox;
chk.Checked = all.Checked;
}
//chkStu.Checked = cbAll.Checked; }
}
这样写报错不存大CheckBox11 展开
//全选及取消 protected void cbAll_CheckedChanged(object sender, EventArgs e)
{
//CheckBox all = sender as CheckBox;
System.Web.UI.WebControls.CheckBox chkStu;
foreach (DataListItem ctl in ddlInfo.Items)
{
if (CheckBox11 is CheckBox)
{
CheckBox chk = CheckBox11 as CheckBox;
chk.Checked = all.Checked;
}
//chkStu.Checked = cbAll.Checked; }
}
这样写报错不存大CheckBox11 展开
展开全部
你还是用 FindControl["CheckBox11"] as CheckBox 来比较好
if (((CheckBox)sender).Checked == true)
{
foreach (DataListItem job in List_Job.Items){
CheckBox cb = (CheckBox)job.FindControl("CheckBox11");
cb.Checked = true;
}
}
else{
foreach (DataListItem job in List_Job.Items){
CheckBox cb = (CheckBox)job.FindControl("CheckBox11");
cb.Checked = false;
}
}
if (((CheckBox)sender).Checked == true)
{
foreach (DataListItem job in List_Job.Items){
CheckBox cb = (CheckBox)job.FindControl("CheckBox11");
cb.Checked = true;
}
}
else{
foreach (DataListItem job in List_Job.Items){
CheckBox cb = (CheckBox)job.FindControl("CheckBox11");
cb.Checked = false;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询