GridView的RowCommand事件方法不执行

 
<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事件方法

蝴蝶刀刀
浏览 393回答 2
2回答

噜噜哒

button用Link类型的
打开App,查看更多内容
随时随地看视频慕课网APP