分享

GridView增删改查之RowCommand事件

 二宝么么哒 2010-12-27
前台页面代码:
 1.在GridView模板列中,添加LinkButton控件(只要是模板控件就行);
 2.在LinkButton控件的属性:
             CommandName属性:del/editor/search/add      //可以自定义
            CommandArgument属性:<%#Eval("ID")%>要绑定的值
 
 
后台CS代码:
    protected void gdvBusiness_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName.ToLower())
        {
            case "del"://删除
                BusinessManager.Del(Convert.ToInt32(e.CommandArgument));
                BindGridView();
                break;
            case "editor"://修改
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='BuesinessEditor.aspx?id=" + int.Parse(e.CommandArgument.ToString()) + "';</script>");
                break;
            case "search"://查询
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='BuesinessInfo.aspx?id=" + int.Parse(e.CommandArgument.ToString()) + "';</script>");
                break;
            case "add"://增加
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>location.href='BuesinessAdd.aspx';</script>");
                break;
            default:
                break;
        }
    }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多