复制代码 代码如下:
<script type="text/javascript">
function checkAll()
{
var checklist=document.getElementsByTagName("input");
for(var i=0;i<checklist.length;i++)
{
if(checklist[i].type=="checkbox")
{
checklist[i].checked=document.form1.ck.checked;
}
}
}
</script>
复制代码 代码如下:
<asp:GridView runat="server" AutoGenerateColumns="false" >
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="产品编号" />
<asp:TemplateField>
<HeaderTemplate>
<input type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
复制代码 代码如下:
protected void 全选_CheckedChanged(object sender, EventArgs e)
{
if (全选.Checked == true)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("checkbox1") as CheckBox;
if (ck!=null)
{
ck.Checked = true;
}
}
}
else
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox ck = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("checkbox1") as CheckBox;
if (ck != null)
{
ck.Checked = false;
}
}
}
}
新闻热点
疑难解答
图片精选