通过一个多选,实现GridView1中全选....
protected void CheckBox2_CheckedChanged(object sender, EventArgs e){
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (CheckBox2.Checked == true)
{
chox.Checked = true;
}
else
{
chox.Checked = false;
}
}
}
这是CS中的代码....为什么找不到..请高手指点... --------------------编程问答-------------------- 我的Gridview 里面分了页..是不是有关系了..是GridView 自带分页功能 .... --------------------编程问答-------------------- 我rseponse.write("i.tostring")
没有什么东西出来... --------------------编程问答-------------------- Response.Write("i.ToString()"); --------------------编程问答-------------------- 找不到什么?
代码写成这样是不是更好一点:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckedBox2.Checked == true)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
//...
}
} --------------------编程问答-------------------- 我试试看... --------------------编程问答-------------------- 还是不行了...555 --------------------编程问答-------------------- ?到底是什么问题?没说清楚 --------------------编程问答-------------------- 看一下我写的吧:
protected void btcheckall_Click(object sender, EventArgs e)
{
if (this.btcheckall.Text.ToString() == "全选")
{
this.cbcheckall.Checked = true;
this.btcheckall.Text = "全不选";
}
else
{
this.cbcheckall.Checked = false;
this.btcheckall.Text = "全选";
}
}
protected void dgidUser_PreRender(object sender, EventArgs e)
{
if (this.cbcheckall.Checked == true)
{
for (int i = 0; i < this.dgidUser.Items.Count; i++)
{
((CheckBox)this.dgidUser.Items[i].Cells[0].Controls[1]).Checked = true;
((CheckBox)this.dgidUser.Items[i].Cells[0].Controls[1]).DataBind();
}
}
else if (this.cbcheckall.Checked == false)
{
for (int i = 0; i < this.dgidUser.Items.Count; i++)
{
((CheckBox)this.dgidUser.Items[i].Cells[0].Controls[1]).Checked = false;
((CheckBox)this.dgidUser.Items[i].Cells[0].Controls[1]).DataBind();
}
}
for (int i = 0; i < this.dgidUser.Items.Count; i++)
{
if (((CheckBox)this.dgidUser.Items[i].Cells[0].FindControl("cbselect")).Checked)
{
this.dgidUser .Items[i].Cells[2].Enabled = true;
}
else
{
this.dgidUser.Items[i].Cells[2].Enabled = false;
}
} --------------------编程问答-------------------- 是不是又是GridView绑定数据那段代码没有写在IsPostBack里面?
如果带分页的话,也只能全选当前页的 --------------------编程问答-------------------- 分页不行的,除非你在分页事件中写
if (CheckedBox2.Checked == true)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
//...
}
--------------------编程问答-------------------- for (int i = 0; i < GridView1.Rows.Count; i++)
{
((HtmlInputCheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked = this.chkSelectAll.Checked;
}
这样写更好一点吧,就不用if判断了 --------------------编程问答-------------------- http://www.cnblogs.com/xiaomi7732/archive/2007/05/10/742270.html --------------------编程问答-------------------- for (int i = 0; i <= dlstGroupUser.Items.Count - 1; i++)
{
CheckBox cbox = (CheckBox)dlstGroupUser.Items[i].FindControl("chek");
if (CheckBox2.Checked == true)
{
cbox.Checked = true;
}
else
{
cbox.Checked = false;
}
} --------------------编程问答-------------------- for(int i = 0; i < GridView1.Rows.Count; i++)
{
((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked=CheckBox2.Checked;
}
CheckBox2的属性必须设定为 CheckBox2.AutoPostBack = true; --------------------编程问答-------------------- 在客户端实现比较好 --------------------编程问答-------------------- postback问题... --------------------编程问答-------------------- 帮顶
补充:.NET技术 , ASP.NET