for (int i = 0; i < this.GridView1.Rows.Count; i++) { CheckBox cb = this.GridView1.Rows[i].Cells[1].FindControl("CheckBox1") as CheckBox; //设定checkbox的选中状态 if (cb != null) { cb.Checked = true; } }
protected void CheckAll_CheckedChanged(object sender,EventArgs e) { CheckBox ck = sender as CheckBox;
if (ck != null) { System.Web.UI.WebControls.GridView g = ck.NamingContainer.NamingContainer as System.Web.UI.WebControls.GridView; for (Int32 i = 0; i < g.Rows.Count; i++) { (g.Rows[i].FindControl("CheckBox1") as CheckBox).Checked = ck.Checked; } } } protected void CheckBox1_CheckedChanged(object sender,EventArgs e) { var count = 0; CheckBox ck = sender as CheckBox; if (ck != null) { System.Web.UI.WebControls.GridView g = ck.NamingContainer.NamingContainer as System.Web.UI.WebControls.GridView; for (Int32 i = 0; i < g.Rows.Count; i++) { if ((g.Rows[i].FindControl("CheckBox1") as CheckBox).Checked) { count++; } } (g.HeaderRow.FindControl("CheckAll") as CheckBox).Checked =count==g.Rows.Count; } }参考
row.FindControl("Checkbox")
{
CheckBox cb = this.GridView1.Rows[i].Cells[1].FindControl("CheckBox1") as CheckBox;
//设定checkbox的选中状态
if (cb != null)
{
cb.Checked = true;
}
}
{
CheckBox ck = sender as CheckBox;
if (ck != null)
{
System.Web.UI.WebControls.GridView g = ck.NamingContainer.NamingContainer as System.Web.UI.WebControls.GridView;
for (Int32 i = 0; i < g.Rows.Count; i++)
{
(g.Rows[i].FindControl("CheckBox1") as CheckBox).Checked = ck.Checked;
}
}
}
protected void CheckBox1_CheckedChanged(object sender,EventArgs e)
{
var count = 0;
CheckBox ck = sender as CheckBox;
if (ck != null)
{
System.Web.UI.WebControls.GridView g = ck.NamingContainer.NamingContainer as System.Web.UI.WebControls.GridView;
for (Int32 i = 0; i < g.Rows.Count; i++)
{
if ((g.Rows[i].FindControl("CheckBox1") as CheckBox).Checked)
{
count++;
}
}
(g.HeaderRow.FindControl("CheckAll") as CheckBox).Checked =count==g.Rows.Count;
}
}参考
呵呵.
autopostback==true
for (int i=0;i<this.Repeater1.Items.Count;i++)
{
HtmlInputCheckBox check = (HtmlInputCheckBox)this.Repeater1.Items[i].FindControl("cbDelete1"); }或者
foreach( RepeaterItem item in this.Repeater1.Items )
{
HtmlInputCheckBox check = (HtmlInputCheckBox)item.FindControl("cbDelete1"); }
foreach (Control c in this.rptTables.Controls)
{
CheckBox cbx = (CheckBox)c.FindControl("cbxId");
if (cbx != null)
{
cbx.Checked = true;
}
}
{
ck1 = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1")
ck1.Checked=true;
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{//复选///////你用Repeater1代替GridView1就可以了
if (CheckBox2.Checked == true)
{
CheckBox2.Text = "全选";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); cbox.Checked = true;
}
}
else
{
CheckBox2.Text = "全不选";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); cbox.Checked = false;
}
}
}
不管你外围用什么控件来包,最终还不是操作checkbox