<script language="javascript">
function SelectAll(tempControl)
{
//将除头模板中的其它所有的CheckBox取反
var theBox=tempControl;
xState=theBox.checked;
elem=theBox.form.elements;
for(i=0;i<elem.length;i++)
if(elem[i].type=="checkbox" && elem[i].id!=theBox.id)
{
if(elem[i].checked!=xState)
elem[i].click();
}
}
</script>
<asp:CheckBox ID="check_all" runat="server" οnclick="javascript:SelectAll(this);" Text="全选" />
for (int i = 0; i < GridView1.Rows.Count; i++) //通过复选框对选定的行进行操作
{
CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); //在当前搜寻当前控件
if (cb.Checked)
{
int id = int.Parse(GridView1.DataKeys[i].Value.ToString()); //获取一个控件值
string sqlstr = "delete from pinglun where postID="+ id + "";
Class1.ExecSql(sqlstr);
}
}