62,074
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 处理全选按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb1 = (CheckBox)(GridView1.Rows[i].Cells[0].FindControl("cb"));
cb1.Checked = CheckBox1.Checked;
}
}
<input type="button" value="全选" onclick="<%= Get全选脚本 %>" />
<input type="button" value="反选" onclick="<%= Get反选脚本 %>" />
protected string Get反选脚本
{
get
{
string scp = "var ids=[";
foreach (GridViewRow r in this.GridView1.Rows)
{
CheckBox ch = (CheckBox)r.FindControl("chb");
if (ch != null)
scp += "'" + ch.ClientID + "',";
}
scp += "''];for(i=0;i<ids.length-1;i++) {var obj=document.getElementById(ids[i]);obj.checked=!obj.checked;};";
return scp;
}
}
protected string Get全选脚本
{
get
{
string scp = "var ids=[";
foreach (GridViewRow r in this.GridView1.Rows)
{
CheckBox ch = (CheckBox)r.FindControl("chb");
if (ch != null)
scp += "'" + ch.ClientID + "',";
}
scp += "''];for(i=0;i<ids.length-1;i++) {var obj=document.getElementById(ids[i]);obj.checked=true;};";
return scp;
}
}
<asp:TemplateField HeaderText="<input type='checkbox' id='chk' name='chk' onclick='checkJs(this.checked);' />全选">
<ItemTemplate>
<input type="checkbox" id="checkboxname" name="checkboxname" value='<%# DataBinder.Eval(Container.DataItem, "Id")%>' onclick='SingleCheckJs();' />
</ItemTemplate>
<ItemStyle BorderColor="White" />
</asp:TemplateField>
protected void chkAllSub_CheckedChanged(object sender, EventArgs e)
{
if (chkAllSub.Checked)
{
foreach (GridViewRow gvrCriterion in gvCriterion.Rows)
{
CheckBox chkGvrSub = (CheckBox)gvrCriterion.FindControl("chkSub");
chkGvrSub.Checked = true;
}
}
ELSE
{
foreach (GridViewRow gvrCriterion in gvCriterion.Rows)
{
CheckBox chkGvrSub = (CheckBox)gvrCriterion.FindControl("chkSub");
chkGvrSub.Checked = FALSE;
}
}
}
//chkAllSub GridView外的checkbox
//chkSub girdview里面的checkbox