现在的位置: 首页 > 综合 > 正文

gredview中全选按钮以及删除

2012年10月14日 ⁄ 综合 ⁄ 共 1298字 ⁄ 字号 评论关闭

编辑模板->头模板和项模板各放一个checkbox,头模板中的改名字,如:all,另一个不用管.

<script type="text/javascript" language="javascript">//脚本实现
    function getAll(chkSelectAll)
    {
        var item = document.getElementsByTagName("input");
        for(i=0;i<item.length;i++)
        {
            if(item[i].type == "checkbox")
            {
                item[i].checked = chkSelectAll.checked;
            }
        }
    }
    </script>

<asp:CheckBox ID="chkSelectAll" runat="server" Text="全选" onclick="getAll(this)"/>//调用的时候

//实现对数据行的操作,如删除时提示确认框.

    protected void gdvAccounts_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
            e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c");
            //((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick","return confirm('确实要删除吗?')");
        }
    }

//实现点击删除按钮,删除复选框选中的行记录

    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow item in gdvAccounts.Rows)
        {
            if (((CheckBox)(item.FindControl("CheckBox1"))).Checked)
            {
                string id = item.Cells[0].Text;
                BLL.DeleteAccounts(id);
                BLL.BindAccounts(gdvAccounts);
            }
        }
    }

抱歉!评论已关闭.