62,074
社区成员
发帖
与我相关
我的任务
分享
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chbSelectRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<input type="button" value="全选" onclick="<%= Get全选脚本 %>" />
<input type="button" value="反选" onclick="<%= Get反选脚本 %>" /><br />
protected string Get反选脚本
{
get
{
string scp = "var ids=[";
foreach (GridViewRow r in this.GridView1.Rows)
{
CheckBox ch = (CheckBox)r.FindControl("chbSelectRow");
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("chbSelectRow");
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;
}
}