checkBox 的全选效果
<script type="text/javascript">
function GetAllCheckBox(CheckAll)
{
var items = document.getElementsByTagName("input");
for (i = 0; i < items.length; i++)
{
if (items[i].type == "checkbox")
{
items[i].checked = CheckAll.checked;
}
}
}
</script>
给checkbox 添加onclick事件
οnclick="GetAllCheckBox(this)"
是否删除选中的数据行Button 的 delete 事件
<script type="text/javascript">
function delte() {
var items = document.getElementsByTagName("input");
for (i = 0; i < items.length; i++) {
if (items[i].type == "checkbox") {
if (items[i].checked == true)
{
return confirm('确认要删除选中的数据吗??');
} else {
alert('请选择要删除的数据!');
return false;
}
}
}
}
</script>
给Button 按钮添加 OnClientClick 事件
后台删除方法
Button 的删除事件
protected void ibtnDelete_Click(object sender, ImageClickEventArgs e)
{
string list = "";
foreach (RepeaterItem rpt in this.rptXXGLList.Items)
{
CheckBox cb=rpt.FindControl("checkBox") as CheckBox;
if (cb.Checked)
{
HiddenField hf = rpt.FindControl("hiddFid") as HiddenField;//主键值
int id = Convert.ToInt32(hf.Value);
list += id + ",";
}
}
string listAll = list + " ";
if (JF_ShowsManager.DeleteList(listAll))
{
Common.Alert(this, "删除成功!");
SearchInfos();
}
else
{
Common.Alert(this, "删除失败!");
return;
}
}
后台代码
//删除选中的所有数据
protected void btndel_Click(object sender, EventArgs e)
{
CheckBox chk;
string id = "(0";
foreach (RepeaterItem Ri in rptE_Comp.Items)
{
chk = (CheckBox)Ri.FindControl("ckbcheck");
if (chk.Checked)
{
HiddenField i = Ri.FindControl("hf") as HiddenField;
id = id + "," + i.Value.ToString();
}
}
id = id + ")";
if (E_companyManager.Delete(id))
{
BintRpt(this.AspNetPager1.CurrentPageIndex);
}
else
{
MessageBox.Alert(this,"删除失败!");
return;
}
}
//选中所有数据
protected void chkAll_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < rptE_Comp.Items.Count; i++)
{
CheckBox chk = (CheckBox)rptE_Comp.Items[i].FindControl("ckbcheck");
if (chkAll.Checked)
{
chk.Checked = true;
}
else
{
chk.Checked = false;
}
}
}