我在Gridview里面 投进了一个buttonfield,请问buttonfield的事件是什么? 在哪里写的?我想通过这个按钮对这一行的记录做一下改变,请告诉我具体怎么设置?

解决方案 »

  1.   

     <asp:ButtonField ButtonType="Button" CommandName="a"
                Text="a" />
    protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    if(e.CommandName=="a")
    {}
    }
      

  2.   

    楼上说了在RowCommand事件中获得点击!
    若CommandName设置为Select,可以在SelectedIndexChanged事件中获得点击
    若CommandName设置为Edit,则可在GridView1_RowEditing事件中获得点击
    等等众多!!
    设置代码:
    <asp:ButtonField ButtonType="Button" CommandName="Select"  Text="按钮" />
      

  3.   

    我按着上面写着做之后 出现
    错误 2 “System.Web.UI.WebControls.GridViewCommandEventArgs”并不包含“RowIndex”的定义
    这是为什么?
      

  4.   

    我大概知道我做错 在哪里了
    应该是 我在这个方法下 取出ButtonField这一行的记录的 主键 有问题 我是这样写的:
    protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    if(e.CommandName=="a")
    {
     int a = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value.ToString());//读出主键
    }
    }请问正确的取出这一行主键方法是什么呢