首页 新闻 搜索 专区 学院

GridView的RowCommand事件方法不执行

0
[已解决问题] 解决于 2012-10-29 15:52
 
<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事件方法

lyricing的主页 lyricing | 菜鸟二级 | 园豆:210
提问于:2012-09-19 18:55
< >
分享
最佳答案
-3

button用Link类型的

lyricing | 菜鸟二级 |园豆:210 | 2012-10-29 15:52
其他回答(1)
0
chenping2008 | 园豆:9836 (大侠五级) | 2012-09-19 21:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册