您的位置:首页 > 其它

GridView增删改查之RowCommand事件

2012-05-12 15:14 274 查看
前台页面代码:
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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: