为了账号安全,请及时绑定邮箱和手机立即绑定

GridView的RowCommand事件方法不执行

GridView的RowCommand事件方法不执行

蝴蝶刀刀 2018-12-07 00:56:35
  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand " AutoGenerateColumns="false" AutoGenerateEditButton="false" > <Columns> <asp:BoundField HeaderText="ID" DataField="id" /> <asp:BoundField HeaderText="NAME" DataField="name" /> <asp:TemplateField HeaderText="Edit"> <ItemTemplate> <asp:ImageButton ID="dd" CommandName="eidt" CommandArgument="hello world" runat="server" ImageUrl="~/edith.bmp" /> <asp:Button ID="ggg" CommandName="edit" CommandArgument="hello" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); DataColumn dc = new DataColumn("id"); DataColumn dc1 = new DataColumn("name"); DataColumn dc2 = new DataColumn("edit"); dt.Columns.Add(dc); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.AcceptChanges(); dt.Rows.Add("1", "lhl", "dd"); dt.Rows.Add("2", "wangqin", "ff"); this.GridView1.DataSource = dt; this.GridView1.DataBind(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "edit") { Response.Write("<script>alert('1111');</script>"); } } } 为什么点击页面上gridview中的按钮,不会执行RowCommand事件方法
查看完整描述

2 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

button用Link类型的

查看完整回答
反对 回复 2019-01-21
  • 2 回答
  • 0 关注
  • 388 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信