前台页面代码:
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; } } |
|
来自: 二宝么么哒 > 《asp.net(C#)》